Creating a large set of random numbers
Show older comments
Hello! I have the following problem. I need to generate 55 705 600 000 unique random numbers uniformly distributed from 0 to 1 (quite a lot, huh?). Usually I have a certain loop and I generate a random number on every iteration. However, that is obviously slow which is why I switched to generating all the random numbers I will need at the start of the program and putting them in a vector element. The problem is that with this huge number (once again, 55 705 600 000) I cannot put them all in one vector because I get an "Out of Memory" message. That leaves me with the only option of generating one random number per iteration of a loop which (combined with the other parts of my code) will take me about half an year to complete!!! Do you have any alternative ideas about how I can speed up the process? Thank you in advance!
Best regards
Accepted Answer
More Answers (2)
You could split your random numbers into, e.g., 557056 vectors of 10^5 random numbers and iteratively work on each 10^5 element vector, which is probably faster than running your algorithm on one random number.
2 Comments
Thorsten
on 21 Nov 2014
The idea is to work on each vector separately; otherwise you would still end up needing > 0.5 TB RAM...
John D'Errico
on 22 Nov 2014
NO! NEVER do that. It is just poor programming style to create many numbered variables. And as Torsten points out, it would still force you to allocate 0.5 terabyte of RAM! Unless you have a supercomputer on your desk, I doubt you have the RAM.
There is no need to create all of those arrays up front. As I explained in my answer, create ONE block of numbers. Use them one at a time. When the last element is used, create another block, overwriting the first.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!