I have a process that returns an unpredictable number of data points, and I'd like to run it repeatedly until I have a certain number of points.
My actual code is too complicated to use an illustration, so I wrote this toy example. fakeData[] will return 1-21 data points, and I want to run it until I have at least 100. But this code doesn't work because you can't take the so-far Length[] of a list that you're still building.
fakeData[n_] := RandomReal[1, 1 + RandomInteger[n]];
big = Reap[
While[Length[big] < 100, (* this doesn't work*)
Sow[fakeData[20]]]][[2, 1]]
I could just allocate 'big' as a Table with length 100 and copy each new small list into it, but then I'd have to discard some perfectly good data points I laboriously calculated, which is distasteful. Is there a better way?
NestWhile[(Join[#, fakeData[20]]) &, {}, Length[#] < 100 &]
work for you? $\endgroup$