Creating a large set of random numbers
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (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 comentarios
Thorsten
el 21 de Nov. de 2014
The idea is to work on each vector separately; otherwise you would still end up needing > 0.5 TB RAM...
John D'Errico
el 22 de Nov. de 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.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!