Posted: Sat May 17, 2008 8:27 am Post subject: [C/C++] Unbiased Randomizing
Hi all. I am writing a card game program, and now I am working on the shuffling of the deck. I have found the Fisher-Yates Algorithm that can shuffle a deck pretty efficiently (according to wikipedia), but it says I need an unbiased randomization. Although I know I can do the srand(time(NULL)); way in C, but I am not sure if it really gives unbiased results. Any help is appreciated and thanks in advance.
Joined: 09 May 2003 Posts: 25968 Location: The netherlands
Posted: Sat May 17, 2008 9:04 am Post subject:
they never give unbiased results.
Best ones you can get are those that take 2 months of calculations to come up with a semi-random value.
But for normal use srand is random enough. For someone to abuse it they'd need to know exactly how many times rand is called before the result is actually used. And calling rand a couple of times (e.g rand times) it makes it harder to guess.
Of course, there's always some fun tools like ce's unrandomizer that can really mess those things up _________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping
I have used the pseudo random generator developed by Makoto Matsumoto for my chess program. I needed the random numbers for my Zobrist keys (http://chessprogramming.wikispaces.com/Zobrist+Hashing).
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum