how to generate true random number

4 views (last 30 days)
hu wong
hu wong on 9 Jun 2017
Commented: David on 8 Jan 2025
Hi everyone: I am trying to generate true random number by MATLAB. I tried the intrinsic functions, 'randn'. But finally, I found it is not true random number generators. I generate 10000 random numbers, found the mean of them are not near 0, some cases the mean are 0.04,0.007 ....they are big. And the sum of the numbers is very big, 87, 73 130 ... So I believe that the function 'randn' is not a true random number generator. Does anyone know how to generate true random number by MATLAB?
  2 Comments
Stephen23
Stephen23 on 9 Jun 2017
Edited: Stephen23 on 9 Jun 2017
" I am trying to generate true random number by MATLAB"
This is a contradiction in terms: all computers (that MATLAB currently runs on) are deterministic.
Some ways to get "true random numbers":
  • Use radioactive decay
  • Use a service like https://www.random.org/, which apparently uses atmospheric noise.
  • Use diode breakdown noise.
  • Buy a book of random numbers.
Or simply accept that the algorithms used by MATLAB are as random as you will need for any modelling that you are doing.

Sign in to comment.

Answers (2)

David Goodmanson
David Goodmanson on 9 Jun 2017
Edited: David Goodmanson on 9 Jun 2017
Hello, hu
yes, Matlab random numbers are not truly random, but they are a very good simulation. The results you are seeing would happen even for a set of truly random numbers. Suppose you take N samples from a given distribution with mean m and standard deviation s. By the central limit theorem, for large N those samples have a normal distribution with mean m and standard deviation s/sqrt(n). So you you should expect some variations from the official mean, even for perfectly random numbers. And those variations should be on the order of 1/sqrt(1e4) = .01.
  3 Comments
David Goodmanson
David Goodmanson on 10 Jun 2017
Hello hu
It depends on what you mean by 'close to 0'. In a random walk model, for N steps you expect that the root mean square distance from the starting point will increase like sqrt(N). If the particle moved with constant velocity then the distance would increase like N. Compared to that, sqrt(N) is close to 0.
sqrt(N) behavior leads to diffusion. If you try to make random numbers with a sum that is artificially smaller than that, then you do not have the standard random walk.

Sign in to comment.


Walter Roberson
Walter Roberson on 9 Jun 2017
  2 Comments
David
David on 8 Jan 2025
Is it possible for MATLAB to tap the entropy source on x86 machines?
If not, it would be nice to add this functionality and have random numbers suitable for cryptography.
As a side note, I suspect that the Sigma-Delta ADC topology was a byproduct of developing similar entropy sources.

Sign in to comment.

Categories

Find more on 乱数発生器 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!