- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
My two dice must be loaded! I get seven way more often than any other number :o
Admin
So in order to increase the randomness of a number, we independently randomize each digit of a 1-100 digit, decimal, 1-100 digit number?
I'd hate to see them come up with a number between 1 and 10 with this strategy. Especially since every number they obtain is going to be anywhere from 0 to 10^100.
Admin
Random() returns increasingly randomer numbers the more you call it.
Admin
omfg
Admin
awful.....just plain awful...
Admin
If I multiply a random by a random and then build a random string with it, then that must make it more random! What a revelation!
Admin
Admin
Well, since the range is so huge, I would have thought that just taking the result modulo ten should give a sufficiently even distribution; it's not like taking a 7-bit random from 0-127 modulo ten where each of the numbers 0-7 get 'one extra chance' to be picked than the others.
However looking at their code, I can only assume they'd generate a random number between 1 and 10 by calling the random routine and repeatedly looping until they got one that fell in range.....
... that could take a little while.
Admin
Knuth devoted an entire section talking about random methods for generating random numbers. It boiled down to this: DON'T
Random numbers are serious business. In cryptography, a secure random number generator can mean the difference between impossible to crack and trivial to break.
This code is just an EPIC FAIL in every way.
Admin
I know I can get even more randomer.
Let rand return a number between 2 and 9. Multiply by 9. Add the digits of the result together. Subtract 5.
This should be as random as I need to get and as everyone knows, a formula is better than just calling rand().
Admin
The obvious solution would have been to set the random seed to a random value a random number of times before using Math.random to make it more randomer
Admin
Admin
To quote Knuth:
"Random numbers should not be generated with a method chosen at random."
Admin
Well I suppose they could do answer % 10 + 1, but I'm sure they have a much more convoluted function that does the same thing.
Admin
Irish I were drunk too. Rowr.
Admin
the more i read this sentence, the less "random" looks like a proper word..
Admin
private int getRandomOverflowException() { return (int) ((Math.random() * 100) * Math.random()); }
Admin
Wonder what they're doing that needs super-extra-ultra random numbers?
Admin
just remember. random * random = ultra-random
Admin
You have GOT to be kidding me! Where's your sarcasm detector?
DUDE...
Admin
Prime numbers are too predictable... Let's make sure we get less of those.
Admin
"Wonder what they're doing that needs super-extra-ultra random numbers? "
They are getting paid by the line of code developed.
Admin
with apologies to xkcd.
Admin
I get that impression with a lot of the WTFs presented here.
Admin
Why not just return '1' every time?
After all, it's theoretically possible that your perfectly-random die rolls repeated 1's. And your callers wouldn't know any different, unless they kept a history (which most don't)
;-)
Admin
Still use Dilberts Random Number Generator:
Nine, Nine, Nine, Nine, Nine, Nine, Nine, Nine.
Admin
I like to sort my random numbers.
Admin
OMGZ that totally equals my birthday! It really DOES work!
Now forward this to 20 friends or u'll have bad luck. LOLZ.
Admin
There, fixed that for ya.
Admin
perhaps it was written by a random code generator
Admin
actachally, taking n sequential samples from a random number generator, you may end up with a less-random number.
Admin
A little bit of knowledge is a dangerous thing.
Admin
they should call those guys HD Random Numbers...for "High Degree" of Randomness. The degree increases as you multiply by more random numbers!
Admin
Apostrophe's and they're use's.
Admin
int getRandomNumber() { int ret; printf("Please throw the dice that you will find under your chair and enter the result"); scanf("%d",&ret); return ret; }
Admin
Admin
So, there is a 1 in 100 chance that the value left of the '.' is 0, and there is a 1 in 100 chance that the value left of the '.' will range between 1*10^100 to 9.999...*10^10 ?
Does true randomness typically lean towards smaller values?
Admin
Admin
I particularly like it how standard generators are not good enough for this "programmer" (despite using them...), but it's OK to have getRandomDigit() heavily biased against returning '9' :-)
Admin
The most random thing about the code is that it's nicely obfuscated. But I think this is what's going on -- forgive me for being obvious, but I really want to know what it does so I never, EVER do it myself.
getRandomDigit does a pretty reliable job of returning one of the ten strings '0' through '9'... I think.
getRandomNumberOfDigits generates a number between 0 and 100, then multiplies it by a number between 0 and 1, generating a significantly less random number between 0 and 100. It converts it to an integer, so the number will probably be between 0 and 99. Converting to integer already does a pretty good job of de-randomizing the number, so the multiplication really just wastes clock cycles.
getRandomDigitString calls getRandomNumberOfDigits to see how many numbers should be in the string. However, getRandomNumberOfDigits could return zero. So it discards 1% of its randomness and equates "zero digits" to "one digit", with that digit being "0". Maybe it only eliminated 0.1% of the randomness.
Finally, take a nearly-random string of 1-99 numbers (with a greater than 1% chance that the string is "0"), add a decimal, add another nearly-random string of 1-99 numbers (again, good odds that the string is "0"), and cram it into a Double.
This is about as good a WTF as you can get. The function works without error, doing exactly what it was programmed to do, but the world would be a better place if it would just throw a "YOU CAN'T BE SERIOUS" error and die.
Admin
fprintf(stderr, "DICE_NOT_FOUND");
Admin
I think a name change for the site is in order. I suggest the Daily What In Tarnation (WIT). Maybe if "wit" were explicitly in the title people would be more inclined to recognize it.
Captcha: caecus
Admin
It's also final so that people can't subclass it and change his logic...
This is a ordered version of 20 runs, note how it goes from very very small, to very very big, very very quickly. Very very.
The numbers look about the same with thousands of runs, very small then very big. I saw a few plain "0"s too.
Admin
There ya go, very small and very big. How random do you want?
It's interesting to note though, that not only do the numbers themselves vary, but so does their randomness.
Admin
I asked my brian to plot a distribution curve of this, and it asplode.
Assuming math.random is evenly distributed between 0.0 <= x < 1.0
then number of digits is going to peak around 25 in't it?
so then your distribution of actual values is some freaky integral of an exponential.
Admin
Admin
that always equals 4. Why not just use xkcd's version, it's less wordy, but has the same result.
Admin
Hey, I DID that. Didn't know random number existed, was using pascal, was years ago, one of my very first programs. You feel ashame when you discover there exist a random() function :/
At least it wasn't professional :D
Admin
I think it was sarcastic.
Admin
This is what I would do:
You just need to do a proper sizing on project start and some cheap labor to roll dice. You could even sell updates to your software supplying new randomness!