Re: Where to get a good seed for srandom()

2005-07-20 Thread Jack Bates
Marcus Watts states: Another way to fix this, is if you're using %, make sure the random value you plug into % is smaller than the largest multiple. For 189, that would be 22724694*189 or 4294967296U. If the number you get is larger than this, discard it and obtain another random number.

Re: Where to get a good seed for srandom()

2005-07-19 Thread Alexander Farber
Hi, that is an interesting (off-)topic :-) May I ask the very last question? If % is not good enough for getting random values in a range, then what is? I see a lot of arc4random() % ... when grepping the /usr/src on OpenBSD. And my (probably too naive) approach to shuffling 32 cards has been:

Re: Where to get a good seed for srandom()

2005-07-19 Thread Marcus Watts
Alexander Farber [EMAIL PROTECTED] asks: ... If % is not good enough for getting random values in a range, then what is? ... Actually, % 32 is fine (or any reasonably small power of 2). Modulo any odd number is guaranteed to have at least a small problem, and module a large enough number is

Re: Where to get a good seed for srandom()

2005-07-19 Thread Hannah Schroeter
Hello! On Mon, Jul 18, 2005 at 11:02:54AM -0700, Jack Bates wrote: [...] 4) Do not use the % (modulo) operator to select a card. The residues from % introduce small amounts of bias, and this is a disqualifying factor for regulated gaming. Does that point still hold, assuming I use a modulus

Where to get a good seed for srandom()

2005-07-18 Thread Alexander Farber
Hi, I'm developing a small multiplayer card game on OpenBSD (but also try to keep it at least compilable on Linux). After 32 cards have been shuffled, each of 3 players gets 10 cards. At the moment I use the sum of time()s when any data has been received from a player as the seed value:

Re: Where to get a good seed for srandom()

2005-07-18 Thread Said Outgajjouft
Artur Grabowski wrote: A good suggestion might be to use arc4random(3) instead of random(3). If the security of your application depends on randomness, you should really pay an expert to help you do it. Randomness is harder than it looks and most likely you will screw it up very badly (a few

Re: Where to get a good seed for srandom()

2005-07-18 Thread Artur Grabowski
Said Outgajjouft [EMAIL PROTECTED] writes: Can you actually only use software code to achieve true randomness? Who cares? You don't need true randomness. You need good enough. What good enough is depends on your application, the potential threats, the sophisitcation of the attackers, the other

Re: Where to get a good seed for srandom()

2005-07-18 Thread Alexander Farber
Thank you for both good advices. Until I have money to pay an expert and my card game isn't using real money... Would arc4random() % 32 be the usual way to get random integers from 0 to 31, or are some bits of the returned value more random than the others? And what is the highest number

Re: Where to get a good seed for srandom()

2005-07-18 Thread Artur Grabowski
Alexander Farber [EMAIL PROTECTED] writes: And what is the highest number returned by arc4random(), is it RAND_MAX? The man page doesn't elaborate on this subject 32 bits. //art

Re: Where to get a good seed for srandom()

2005-07-18 Thread Damien Miller
Alexander Farber wrote: Hi, I'm developing a small multiplayer card game on OpenBSD (but also try to keep it at least compilable on Linux). After 32 cards have been shuffled, each of 3 players gets 10 cards. At the moment I use the sum of time()s when any data has been received from a

Re: Where to get a good seed for srandom()

2005-07-18 Thread Jack Bates
Good day: I happen to be very familiar with this subject, having developed, analyzed and qualified two different card-shuffling algorithms for real-money play in the online card game business. There is a fair bit of literature on this subject. Some tips that I can share without breaking an NDA: