I would need some (a lot of) help to improve/rewrite some code.
Since my real problem is a bit too complicated to explain, I'll try to show a simplified scheme of what I want to achieve.
I create some random numbers on an interval between 0 and 1 with:
maximumRandomNumberFirstStep=10000; randomNumberFirstStep=RandomReal[{0,1},maximumRandomNumberFirstStep]; Out of some reasons, I am only interested in values which are higher than a special limit value. So, I am searching for these values with:
limitValue=0.5; helpListFirstStep=ParallelTable[If[randomNumberFirstStep[[i]]<limitValue,i,0], {i,1,maximumRandomNumberFirstStep}]; For all values which are lower than this limit value, I want to generate some new random numbers. At the moment I am doing this with:
maximumRandomNumberSecondStep=maximumRandomNumberFirstStep-Count[helpListFirstStep,0]; randomNumberSecondStep=RandomReal[{0,1},maximumRandomNumberSecondStep]; Now, I want to add the new random numbers (randomNumberSecondStep) to all the old random numbers (randomNumberFirstStep) which are below my limit value. I am doing this with this very ugly code:
j=1; randomNumberSecondStep2=Table[If[ helpListFirstStep[[i]]==0, {randomNumberFirstStep[[i]],0}, {randomNumberFirstStep[[i]]+randomNumberSecondStep[[j]],j++} ],{i,1,maximumRandomNumberFirstStep}]; randomNumberSecondStep2=randomNumberSecondStep2[[All,1]]; (by the way, this code does only work with Table but not with ParallelTable if I execute it more than once; perhaps somebody has also a solution for that)
If one creates a histogram Histogram[randomNumberSecondStep2], it can be seen,= that there are still values which are below my limit value. So, I have to copy my code from above, rename Second to Third and execute it again. I am doing this so often until none of my randomNumberNthStep2-values are below my limit value.
This works, but I think it cannot be programmed worse than I am doing it (copying, renaming etc. is really ugly, especially if your real problem is more complicated because of more variables).
So, how can I write a better program in which all the copying and renaming steps can be avoided? I think there should be a solution in which all these steps are executed automatically. Unfortunately, my programing skills are too low to develop a nice solution.
lowerlimitis the lower bound you wish to use? $\endgroup$Ifs. It's hidden in the default view and you'll have to scroll to the side to see{randomNumberFirstStep[[i]]+randomNumberSecondStep[[j]],j++}. ANestWhilewould probably be of help here. Not going to work on it now though. $\endgroup$Ifis important since I need the randomNumberNthStep2-values. And thanks for the hint with NestWhile. If I find a solution by myself (that would be a miracle ;-), I am going to post it for sure! $\endgroup$