- 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
But... rand() & 16 is either 0 or 16!
Admin
Does a higher entropy mean more ordered? or less ordered? Ouch, I'm getting chaos in my head. This looks all random to me.
Admin
Admin
Wonderful!
Admin
Admin
Yes :-)
Admin
This reminds me of the much easier implementation I have seen somewhere (but, alas, can't remember where):
Admin
XKCD http://xkcd.com/221/
Admin
Admin
http://xkcd.com/221/ of course ;-)
EDIT: Ok, beaten to it twice!
Admin
Cloud computing sounds random to me; we should obviously hit the network whenever we need a random value.
Admin
The interesting thing is, if you give it the same seed, it will produce the same 'random' number each time. Now for a randomizer for the seed ;-)
Admin
Admin
But... how can you ever get enough entropy when it's always increasing in the universe? Shouldn't that be an infinite loop?
Admin
In Oceans13.dll (http://www.imdb.com/title/tt0496806/) ?
Admin
I think we have a new record!
The time between a new WTF article and first reference to XKCD...
Admin
Just in case some people may not be clear on the need for "random" numbers to be as close to really random as possible:
In most applications, like Windows solitaire or even playing good ol' rogue, it doesn't really matter. BUT, I'm sure many of us could think of scenarios where someone could take your money/secrets/whatever by predicting the "random" number. For example, generating crypto keys, or dealing cards in an online gambling site. In such cases, you don't want to settle for plain old "rand() seeded with the time". Most trivial psuedo-random-number generators (PRNGs) are so mechanistic that given a few outputs, the next output can be predicted with high confidence. Usually it's a simple function of the previous value. A more-random (i.e., closer to truly random) generator will incorporate additional "entropy" (no I'm not going to explain that). There are assorted tests for how random a RNG/PRNG's output is.
Admin
The worst thing is that if you happen to run code that tries to increase randomness in an environment where you have a hardware-entropy based random number generator, the code actually consumes the entropy!
Admin
Admin
In the right place I would be reading that and nodding to myself. As a reply to this piece of code, not so much, it just sounds like you are repeating something smart you said because that piece of code does not DO that.
Admin
Admin
Admin
What would improve this program?
A. More entropy B. Less entropy C. More randomness D. More cowbell E. None of the above
Admin
why noone fills in title attribute when reposting images from xkcd
Admin
If you really want to increase the entropy: http://www.fourmilab.ch/hotbits/
Admin
Your still just jumping into the same random tables follwoing a well-defined path on the random number selection.
Admin
This is just a random comment
Admin
4
Admin
Dave
Admin
According to Debian, there are only 32766 random numbers.
Admin
There were some well-publicised problems with random-number generators in the past - e.g. this - but I hardly think this is the answer..! If your compiler's rand() function doesn't generate sufficiently-random numbers, get a better compiler.
Admin
Admin
How about just hash the latest Twitter post? Even human readers consider the Twitterstream pretty random.
Admin
To generate a random hash, just hash the string "random"
Admin
Where do you get the query from? Obviously it has to be a dictionary word, since nonsense will always fetch the same result page (No results found).
Then you'll have to account for events like network or service outages...
...Or maybe you were kidding...
Admin
I'd rather a nice corned-beef hash...
(ha! beat that for random :P)
Admin
Admin
They are guaranteed to be random - on a fair d20 dice.
Admin
Whoops...I thought too much about it.
Admin
At a minimum, the page will always be different because it includes your original string in the "No Results Found for X" - so it will always be slightly different, which should make a difference when hashed.
Or maybe you were kidding too.
Admin
I have created a web service to get the NY Lottery numbers. That is what I use for random numbers.
Admin
I like the flow of his comments:
I can see him on the quarter-mile thinking, "On the mark... rev the engine... pop the clutch!"Admin
Or you could use a bit of atmospheric noise (like what is generating the die rolls here) to generate true random numbers.
Admin
In all seriousness, some people need it forced into them that calling rand() multiple times for one random number makes it LESS random, by massively shortening the time until the prng's sequence repeats. Taking a stupidly extreme example, a prng that only produces the following two numbers in never-ending sequence when given the seed "42": 6 9 6 9 6 9 6 9... What do you get if you decide that that's not random enough and xor together two numbers every time instead? That's got to be more random right? Look: 6^9=15 6^9=15 6^9=15 6^9=15. We go from 2 numbers repeating to 1 number! How about xoring together a random number of numbers? More random, surely! Look: (6 numbers)(9^6^9^6^9^6) = 15 (9 numbers)(6^9^6^9^6^9^6^9^6) = 6 (9 numbers)(6^9^6^9^6^9^6^9^6) = 6 6 6 6. Lovely, it loops to the same number after the second call!
The only way to make it more random is to give it more data (entropy). e.g. take a 1024 element array of numbers and use the value from shitty-prng to step through it (using that primes trick to make sure that you go through all the numbers no matter what the step number is). Suddenly you can get a 1024 number sequence from a prng that only outputs 6 and 9!
Or you could just implement or use an existing implementation of the mersenne twister prng, with it's 2^19937 − 1 long number sequence and 64-bit output. Or another, if you need to. Whatever you do, don't try to make a prng of your own without a degree in number theory.
Admin
As someone else mentioned about this particular block of code, giving it the same seed will always have it output the same number in return. Honestly, it's no better than a standard prng (obviously, it's much worse).
In this method, however, the number is STRICTLY defined by the number given to it as a seed. There is no other factor. This method will never produce a random number.
Why do people seem to think that constantly reseeding will guarantee something is more random than simply seeding the number generator once?
Admin
Along with Hotbits, there's Random.org.
Admin
The stupied thing in that code is that the guy forces the implementation to reseed the generator at each call. I'd bet my hands everywhere in the code the generator is seeded with time(NULL) or derivatives
Admin
Switching compilers for a different rand() function seems rather extreme and pointless...
Admin
EAGCI CAQCK HYCUC PEXBU BXIUK GJRGT KKTRN CUNSW YAVBV YQZWS UYPCS AJCRP VCAPT NROBK KALGB GESGA KAYAC RAMUS CQUCF OPXCR HNSST TZXMF YXFXY IOYUI RWYLZ EZPBC GJPYC JSBHF GFCMC AURZP AQMZC LDCAF EHOUG REZSL EZRGL UHFLG VMXHL ZTPBT VGBKA HBEGT QLSHS EBZJN GEZEM LDFAF ZWLAG MIHRO BHAUP SYQSI EZMDD YOHEP MDLYD SKLZC ABKAV ZTUQL CUKPY NONVS DHVPF ZHQKH TLIDM EDFZU QBPBR NPFBK XESTT YSAPD IIPQL BVPGU JXWYZ NMOSN ZQRRK LQDMF HUNWL ZXGOE BYBYW ALJPE WOVOG GZWJL BRGPO ROLYD QABSY YSKII PEXKT DRTAB FBSLQ GCFSB IIBKA AJTKR CZWZK PCBIC CNEVZ VBBAT DJCEU CFEWP VYPSX AIABQ DEEIZ DDAFE UIOWN IZTNW IIUYB SYJTA AWEEF DIIEO NYWBV KKVDX RMGML IFKRZ KRWOW BREKV SXUPZ PAKLE IDRPQ CXVMO UXGQL CSDHC YAATQ ZJRKU VSXNH NQFJC UEZAV LDNOL QNLQG BPPTZ KOSHB ZVSFF UZKUZ FGDTU OJHZZ OBPEU POJHW LHSDM XYLHT LNZOG UCQCC QQEFU ZVJIC FUKXY WVWID QTQPI XJLOL NECSK XRFGA ILUSJ TPEQX HGRYW ZWGKK SYOUR YRIEX IMJDE SXTXN RETID PIZVT JNRYI IXARB XAOHE SABMX OEBIM FYVET OOHGM PPKPG LNHAV LTVNG SCKUK XZISE CGSKM FABQQ ICEPC ZBVVO BNQLI BIIKB NMHGW ULWVB NEERT GQUBL JCZZO IBXQL YDXFJ UAVRW XEABV UHMPJ YYMXY AFZYW LWZIC JDCFV YDAYE VTMII WGGID FJJEH FPDFY GPCIU YGXYF CUYPC HLJNT NSDWX KCNOH MUXPC RNJPL PSFOH IVSRJ MECPB AADNO
Admin
Only case where I'd suggest to call rand() multiple times: is that if you need 64bit number, but rand() generated 32bit number (or any other case where rand() generates less than you need). And do something like this a = rand() b = rand() result = a shl 32 + b
Or you have better solution for this? (Without writing my own prng)