+ 4
how do I make the cpu generate a true random number in javascript?
Thanks in advance.
4 Answers
+ 4
Technically there is no number that can be created by man or machine that is truly random. The best we can do is create functions so complex that they seemingly return random values, however they are never truly random.
That being said there is the Math.random() method that will return a random number between 0 and 1 (non-inclusive).
To generate random numbers between 0 and a higher limit just multiply Math.random() by the upper limit you want.
example:
var x = (Math.random() * 100) + 1
will give you a number between 1 and 100
+ 4
There is a seed function in C++ that helps generate a True random number using the internal clock as a seed. It means that the cpu generates a number based on the seed from the clock, which is always changing, hence giving a different number each time - That is what true random means.
Question is, how can I do it in javascript.
And the random functions of Java and C# are also giving true randoms numbers.
0
Š²ŃŠµŠ¼ ŠæŃŠøŠ²ŠµŃ.ŠŗŃŠ¾ Š·Š½Š°ŠµŃ ŠŗŠ°Šŗ ŃŠ¾Š·Š“аŃŃ ŃŠŗŃŠøŠæŃ ŃŃŠ¾Ńн???