Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C/C++] Unbiased Randomizing

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Aikos
Cheater
Reputation: 0

Joined: 26 Nov 2007
Posts: 47

PostPosted: Sat May 17, 2008 8:27 am    Post subject: [C/C++] Unbiased Randomizing Reply with quote

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.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 474

Joined: 09 May 2003
Posts: 25968
Location: The netherlands

PostPosted: Sat May 17, 2008 9:04 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
Aikos
Cheater
Reputation: 0

Joined: 26 Nov 2007
Posts: 47

PostPosted: Sat May 17, 2008 11:48 pm    Post subject: Reply with quote

Thanks DB. The info is very helpful.
Back to top
View user's profile Send private message
4ng3licDew
Cheater
Reputation: 0

Joined: 14 Feb 2008
Posts: 28

PostPosted: Sun May 18, 2008 2:34 am    Post subject: Reply with quote

You can read more about pseudorandom number generator from wikipedia:
http://en.wikipedia.org/wiki/Pseudorandom_number_generator

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 can get the C source code for the pseudo random generator from here:
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html

Please note: This pseudorandom number generator is not cryptographically secure "as is". Please read FAQ from Mersenne Twister Home Page:
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites