User Name: Password:
New User Registration
Moderator: SueQ , coan.net 
 Backgammon

Backgammon and variants.

Backgammon Links


Messages per page:
List of discussion boards
You are not allowed to post messages to this board. Minimum level of membership required for posting on this board is Brain Pawn.
Mode: Everyone can post
Search in posts:  

13. October 2012, 05:46:42
playBunny 
Subject: Re: Lots o' fives
Aganju: Part of my masters degree was about 'Pseudo random numbers', how to make them and how to analyze the quality. It's been a while, though.

It must have been a few decades ago if they were using the time as a seed for each random number.

Except that even then the time wasn't used to obtain each random number because you don't seed for each random number, you seed the generator once, when you first start using it.

Aganju: the routine uses the current time as seed or so. If you make many moves within a minute, all your opponents get the same roll.

So that's balderdash and gives me every reason to doubt that you studied random number generators in any depth, if at all. Generated numbers have got nothing to do with the time and everything to do with the position in the sequence which, of course, changes every time you pluck a number out. That's even assuming that a mathematical random number generator is being used in the first place, which isn't necessarily the case.

Furthermore, if some junior programmer did make the mistake of reseeding the generator before every number, they'd have to be an idiot to take the computer time - accurate to milliseconds, if not microseconds or nanoseconds, and throw most of it away just to use the minute!

Fencer, by the way, isn't even remotely a junior programmer, nor is he an idiot, although pgt's observation is, unfortunately, correct.

13. October 2012, 10:13:25
pgt 
Subject: Re: Lots o' fives
playBunny: I enjoyed your contribution, erudite Bunny. Perhaps you should be elevated to "Play Rabbit"

13. October 2012, 14:36:42
Aganju 
Subject: Re: Lots o' fives
playBunny: I think you misunderstood me. Of course, seeding every time as well as seeding only with the minutes is not a good idea; this was my try to reverse-engineer the experienced behavior here on BK. As I wrote below, if I play a move in five games within one minute, all my opponents have the same roll afterwards. That seems to point to
a) the roll for the opponent is made the moment I send my move, and
b) the minute is used for seeding every time,
so that would explain why they all have the same roll. That's only a guess, of course, but one that explains what's happening.
Because all my opponents answer at different times, typically this is not very obvious, but if you note it down, you can check the games and verify that they all roll equal.

A good (pseudo-)random number generator consists of multiplying a stored number with a large prime, and dividing by another large prime, the division result is stored for the next round, and the division rest is normalized to be used as the 'random' number. The quality and equal distribution of the resulting sequence depends on the choice of the two primes, and as part of my work, we analyzed all primes up to 1 billion for their resulting random number quality. I have kept the best result (I hope), and will look it up later and post it here.

I know that Fencer is rather good at what he does, and I know that a lot of people whined already about the random numbers here on BK, so I just gave up complaining myself. I just answered to someone else's comment about five times 5-5 in a row, and that it is unfortunately quite common to see that in opponents rolls if you play fast.
...

Here is the C++ code from ~2001 with the best possible random numbers for numbers below 1 billion. It will return a
double between 0 and 1, and needs to be normalized to the target interval (backgammon: 1-6).

double Rnd::Double (void)
/* Linearer Kongruenzgenerator nach Afflerbach
x[i+1] = x[i] * 27132 + 1 (mod 62748517), z[i] = x[i] / 62748517
Periodenlaenge 62748517, Beyer-Quotienten 0.969, 0.922, 0.819
Bestmoegliche Verteilung fuer Modul m <1e9 */
{
static unsigned long xi = 0;
int i;
unsigned long z = 0;

if (xi == 0) xi = (unsigned long) time(NULL);

for (i=30; i>0; i--) {
z <<= 1;
if (xi & (1L << (i-1))) z += 27132L;
while (z> 62748516L) z -= 62748517L;
}
xi = z + 1L;
return ((double) xi / 62748517.0);
}

Date and time
Friends online
Favourite boards
Fellowships
Tip of the day
Copyright © 2002 - 2024 Filip Rachunek, all rights reserved.
Back to the top