View Full Version : How random is Math.random()
firegambler
October 20th, 2004, 05:09 PM
Hi,
I always wondered, how a random gererator is programmed and
I always doubted that the numbers were random.
So I made a file to test how random Flash's random numbers are.
The film generates random numbers, counts their frequency, and shows them in a bar-chart.
There are 20.000 items generated, so I think that this is fair enough to have a statistically relevant result.
(see LINK (http://www.koschitz.org/firegambler/randomtester.html) or attached files)
See for yourself,
when I try, the numbers have a very high tendency towards one!
What do you think?
thoriphes
October 20th, 2004, 05:16 PM
quite interesting....
it doesn't like choosing lower values.
RvGaTe
October 20th, 2004, 06:56 PM
good testing, only high values here to...
edit: let it go faster, im waiting my *** off for the 20.000... :P
edit2: every tried the same with random(min, max), maybe thats more random...
edit3: done, its doing 20.001 :P, here's the result.
edit4: aarg... removed the screenie :)
firegambler
October 20th, 2004, 07:05 PM
Yep, that is about how my results look too.
I improved the speed a bit (by 20%) but since the test uses an onEnterFrame-function it reaches its speedlimit at 120 fps.
Sorry, couldn't get it running any faster. ;)
Yeldarb
October 20th, 2004, 07:08 PM
Wow, that is interesting, nice work :)
firegambler
October 20th, 2004, 07:14 PM
I guess I have to apologize,
I found a bug in the script that might cause the slope. :blush: :blush: :blush:
Click to see the corrected version (http://koschitz.org/firegambler/randomtester.html)
Man I'm so embarrassed! :blush::blush:
Yeldarb
October 20th, 2004, 07:17 PM
What was the bug?
kirupa
October 20th, 2004, 07:19 PM
I guess I have to apologize,
I found a bug in the script that might cause the slope. :blush: :blush: :blush:
Click to see the corrected version (http://koschitz.org/firegambler/randomtester.html)I ran it only for about 20000, but your new version seems a bit more random. I didn't see the slope that I found in the earlier version :)
firegambler
October 20th, 2004, 07:20 PM
Basically every bar should grow by one each time its number is generated.
Unfortunately in my first script it didn't grow by a fix value but was infected by its index so that bars with higher indices grew faster...
Fact
October 20th, 2004, 07:22 PM
At first i thought that Math.random() seemed to go for the higher number(your bugged version) , but now that youve fixed it , i now know , Math.random() is random :D LOL
firegambler
October 20th, 2004, 07:22 PM
I ran it only for about 20000, but your new version seems a bit more random. I didn't see the slope that I found in the earlier version :)
Yeah, I guess Math.random() is random,
sometimes my scripting skills are random too! :D:D:D
RvGaTe
October 20th, 2004, 08:03 PM
seems random now... :)
thoriphes
October 20th, 2004, 08:35 PM
I guess I have to apologize,
I found a bug in the script that might cause the slope. :blush: :blush: :blush:
Click to see the corrected version (http://koschitz.org/firegambler/randomtester.html)
Man I'm so embarrassed! :blush::blush:
haha, that little bug almost made me lost my faith in the function :P
Yeldarb
October 20th, 2004, 09:10 PM
Is it just me or is someone's footer on this page making random squeeky noises?
MTsoul
October 20th, 2004, 09:11 PM
Doesn't work in firefox!
Nonetheless, very kool. How random is the random number between certain integers? ;)
senocular
October 21st, 2004, 06:13 AM
This has been done before, and the person who did it (I keep forgetting who everytime this is brought up) made a Excel chart and everything. Try searching the forum to find those results. Pretty interesting.
firegambler
October 21st, 2004, 06:32 AM
I searched all 150 search results containing the word 'random'.
Couldnt find anything though :(
ben_is_sparky
October 21st, 2004, 07:36 AM
This is cool - it looks really weird - would make a nice footer...
Sammo
October 21st, 2004, 07:45 AM
Doesn't work in firefox!
Nonetheless, very kool. How random is the random number between certain integers? ;)
It does work in FireFox...
firegambler
October 21st, 2004, 08:50 AM
For all interested ones:
I made it calculate the average and the deviation value every 1000 items.
randomtester (http://www.koschitz.org/firegambler/randomtester.html)
<hint> It might take a couple of seconds to do the calculation </hint>
hificopymaster
October 21st, 2004, 12:54 PM
You know technically, Math.random() is not random at all. It's pseudo-random. It doesn't actually have a big hat full of numbers from which it closes its eyes and picks one. :P
λ
October 21st, 2004, 01:45 PM
You know technically, Math.random() is not random at all. It's pseudo-random. It doesn't actually have a big hat full of numbers from which it closes its eyes and picks one. :P
Well, it depends ;) If you have some very expensive hardware and run on Linux, it might be :)
hificopymaster
October 21st, 2004, 01:50 PM
I always thought that it was impossible to get truly random numbers. There's always some type of formula used to generate them. It's just that the more advanced random methods will make it almost impossible to guess what's coming next, so they're considered "random enough" for most purposes. But as long as there's a formula, and you know what that formula is, and you have enough time on your hands, you can always figure out the next number, can't you?
Unless you're saying Linux boxes actually have hats inside... :P
[m]
October 21st, 2004, 01:56 PM
Jup. It's calculated with some gismo doohicky flipflop processor stuff.
they_played_tri
October 21st, 2004, 02:09 PM
']Jup. It's calculated with some gismo doohicky flipflop processor stuff.
I read about those, very technical. But microsofts new plans to unveal the biochip ( midget in a box ) got bad press something-or-other regarding human rights. Couldnt quite understand myself.
My random number chart came up with 0 before it crashed. The joys of P2 233's and 32Mb o ram. Stable as a house of cards in a hurricane.lol
λ
October 21st, 2004, 02:14 PM
You can get internal cards that tune into radio static and then produce random numbers out of binaryizing that. I think numbers generated by that would be truly random.
If you had one of these cards and it had Linux hardware support, then it is likely that all programs would use the "true" random numbers due to the way that Linux implements random numbers - this would most likely include Flash :)
firegambler
October 21st, 2004, 04:50 PM
You know technically, Math.random() is not random at all. It's pseudo-random. It doesn't actually have a big hat full of numbers from which it closes its eyes and picks one. :P
Well, even if it is not really random, it must be quite a good function 'cause the average is always very, very close to 0.5
What irritates me a bit is that the deviation's value vary in a strange way ...
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.