Comment On Random Stupidity

Originally posted by "snoofle" ... [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Random Stupidity

2008-03-10 10:07 • by yer mom (unregistered)
My two dice must be loaded! I get seven way more often than any other number :o

Re: Random Stupidity

2008-03-10 10:07 • by Trevor (unregistered)
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.

Re: Random Stupidity

2008-03-10 10:13 • by akatherder
Random() returns increasingly randomer numbers the more you call it.

Re: Random Stupidity

2008-03-10 10:15 • by Bob (unregistered)
omfg

Re: Random Stupidity

2008-03-10 10:15 • by mack (unregistered)
awful.....just plain awful...

Re: Random Stupidity

2008-03-10 10:17 • by Erick
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!

Re: Random Stupidity

2008-03-10 10:20 • by Gabriel Kiss (unregistered)
182424 in reply to 182423
Erick:
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!

yes it more random because you get a RANDOM^2 number!!!11one-eleven... and so on :)

Re: Random Stupidity

2008-03-10 10:29 • by DaveK
182430 in reply to 182415
Trevor:
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.


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.

Re: Random Stupidity

2008-03-10 10:29 • by Some Computer Scientist (unregistered)
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.

Re: Random Stupidity

2008-03-10 10:31 • by KattMan
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().

Re: Random Stupidity

2008-03-10 10:31 • by Brian S (unregistered)
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

Re: Random Stupidity

2008-03-10 10:33 • by TraumaPony (unregistered)
182435 in reply to 182418
akatherder:
Random() returns increasingly randomer numbers the more you call it.

Actually, depending on the algorithm, the more times you call it, the more predictable it becomes.

Re: Random Stupidity

2008-03-10 10:48 • by Anon (unregistered)
To quote Knuth:

"Random numbers should not be generated with a method chosen at random."

Re: Random Stupidity

2008-03-10 10:54 • by shadowman
182438 in reply to 182415
Trevor:
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.


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.

Re: Random Stupidity

2008-03-10 10:58 • by gblues
Irish I were drunk too. Rowr.

Re: Random Stupidity

2008-03-10 10:59 • by A Nonny Mouse
182441 in reply to 182433
Brian S:
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


the more i read this sentence, the less "random" looks like a proper word..

Re: Random Stupidity

2008-03-10 11:03 • by Colin (unregistered)
private int getRandomOverflowException() {
return (int) ((Math.random() * 100) * Math.random());
}

Re: Random Stupidity

2008-03-10 11:09 • by MAV (unregistered)
Wonder what they're doing that needs super-extra-ultra random numbers?

Re: Random Stupidity

2008-03-10 11:10 • by MAV (unregistered)
just remember. random * random = ultra-random

Re: Random Stupidity

2008-03-10 11:11 • by RobIII (unregistered)
182447 in reply to 182435
TraumaPony:
akatherder:
Random() returns increasingly randomer numbers the more you call it.

Actually, depending on the algorithm, the more times you call it, the more predictable it becomes.


You have *GOT* to be kidding me! Where's your sarcasm detector?

DUDE...

Re: Random Stupidity

2008-03-10 11:11 • by John the incredible (unregistered)
Prime numbers are too predictable... Let's make sure we get less of those.

Re: Random Stupidity

2008-03-10 11:12 • by Geezer coder (unregistered)
182449 in reply to 182445

"Wonder what they're doing that needs super-extra-ultra random numbers? "

They are getting paid by the line of code developed.

Re: Random Stupidity

2008-03-10 11:13 • by Patrick (unregistered)


with apologies to xkcd.

Re: Random Stupidity

2008-03-10 11:15 • by N (unregistered)
182452 in reply to 182449
I get that impression with a lot of the WTFs presented here.

Re: Random Stupidity

2008-03-10 11:15 • by Recycled contractor (unregistered)
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)

;-)

Re: Random Stupidity

2008-03-10 11:23 • by Xandax
Still use Dilberts Random Number Generator:

Nine, Nine, Nine, Nine, Nine, Nine, Nine, Nine.

Re: Random Stupidity

2008-03-10 11:50 • by bramster (unregistered)
I like to sort my random numbers.

Re: Random Stupidity

2008-03-10 11:53 • by Nerf Herder (unregistered)
182462 in reply to 182432
KattMan:
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().



OMGZ that totally equals my birthday! It really DOES work!

Now forward this to 20 friends or u'll have bad luck. LOLZ.

Re: Random Stupidity

2008-03-10 11:54 • by APH (unregistered)
182464 in reply to 182440
gblues:
Irish I were drunk too. Rowr.

Irish she were drunk too. Rowr.

There, fixed that for ya.

Re: Random Stupidity

2008-03-10 11:59 • by my name is missing (unregistered)
perhaps it was written by a random code generator

Re: Random Stupidity

2008-03-10 11:59 • by grg (unregistered)
actachally, taking n sequential samples from a random number generator, you may end up with a less-random number.

Re: Random Stupidity

2008-03-10 12:07 • by Raedwald
A little bit of knowledge is a dangerous thing.

Re: Random Stupidity

2008-03-10 12:12 • by Brandon (unregistered)
they should call those guys HD Random Numbers...for "High Degree" of Randomness. The degree increases as you multiply by more random numbers!

Re: Random Stupidity

2008-03-10 12:16 • by Grammar Nazi (unregistered)
Apostrophe's and they're use's.

Re: Random Stupidity

2008-03-10 12:26 • by Richard (unregistered)
182477 in reply to 182471
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;
}

Re: Random Stupidity

2008-03-10 12:34 • by yer mom (unregistered)
/**

* We all know that random number generators aren't truly random.
* This function generates random numbers a bit more randomly by using a hardware source.
*/
int random() {
FILE* fp;
char count;
float final = 0;
char i;

fp = fopen("/dev/null", "r"); /* open hardware source */
count = fgetc(fp); /* more randomly */
for (i = 0; i < count; i++) {
final *= ((float)fgetc(fp)) / 255.0;
};
};

Re: Random Stupidity

2008-03-10 12:38 • by kw (unregistered)
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?

Re: Random Stupidity

2008-03-10 12:43 • by Random832

int getRandomNumber() {
return 4; // chosen by fair dice roll, guaranteed to be random.
}

Re: Random Stupidity

2008-03-10 12:45 • by me (unregistered)
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' :-)

Re: Random Stupidity

2008-03-10 12:56 • by RobertB
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.

Re: Random Stupidity

2008-03-10 13:09 • by KT (unregistered)
182496 in reply to 182477
Richard:
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;
}


fprintf(stderr, "DICE_NOT_FOUND");

Re: Random Stupidity

2008-03-10 13:10 • by IV (unregistered)
182498 in reply to 182435
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

Re: Random Stupidity

2008-03-10 13:11 • by Maybe Anon (unregistered)
182499 in reply to 182487
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.


0.5215661175298943
4.134056449938214
6.0
87.0
5785.430245466055
7595.48417053833
110939.37712878542
488733.77795
5.352956622495464E10
9.462390630556685E10
1.2070032004517574E13
5.2092107513286E13
9.157946886121803E13
2.9497107991280284E25
1.834136407474311E32
1.7446213245558947E41
8.45034288762292E43
6.632080987216593E58
8.500084477175984E67
2.1875718001884665E72

Re: Random Stupidity

2008-03-10 13:37 • by sweavo (unregistered)
182509 in reply to 182499
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.

Re: Random Stupidity

2008-03-10 13:45 • by sweavo (unregistered)
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.

Re: Random Stupidity

2008-03-10 13:45 • by snoofle
182512 in reply to 182490
RobertB:
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.

Hi there - OP here. I can't believe nobody mentioned that no routine that depends upon a random number generator can ever really be any more random than the underlying generator being used. In other words, assuming that the routine is implemented perfectly (as many have pointed out, it's not), it can never be any more random than: Math.random()

Re: Random Stupidity

2008-03-10 13:46 • by Derek (unregistered)
182513 in reply to 182432
KattMan:
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().



that always equals 4. Why not just use xkcd's version, it's less wordy, but has the same result.

Re: Random Stupidity

2008-03-10 13:49 • by tchize
182516 in reply to 182477
Richard:
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;
}


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

Re: Random Stupidity

2008-03-10 13:49 • by Nerf Herder (unregistered)
182517 in reply to 182513
Derek:
KattMan:
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().



that always equals 4. Why not just use xkcd's version, it's less wordy, but has the same result.


I think it was sarcastic.

Re: Random Stupidity

2008-03-10 13:50 • by Felix (unregistered)
This is what I would do:

int counter = -1;
public int getRandomInt() {
counter++;
switch (counter) {
case 0:
return 4;
case 1:
return 2;
case 2:
return 5;
case 3:
return 4;
//and so on
default:
//this can't happen anyway....
throw new SomeException();
}
}

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!
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment