A simple PRNG using /dev/urandom

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Linux on older Macs

Post by sje »

Linux on older Macs

I've tried a couple different PowerPC Linux distributions on older PPC Macs. As I recall, in every case there was something broken or missing: WiFi, sleep, sound, etc. Perhaps things have improved in recent times.
matthewlai
Posts: 793
Joined: Sun Aug 03, 2014 4:48 am
Location: London, UK

Re: Linux on older Macs

Post by matthewlai »

sje wrote:Linux on older Macs

I've tried a couple different PowerPC Linux distributions on older PPC Macs. As I recall, in every case there was something broken or missing: WiFi, sleep, sound, etc. Perhaps things have improved in recent times.
That sounds a little strange, since Macs are the most common PPC computers out there (for desktop Linux at least), you would think they would be well tested.
Disclosure: I work for DeepMind on the AlphaZero project, but everything I say here is personal opinion and does not reflect the views of DeepMind / Alphabet.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Ten million random games

Post by sje »

Ten million random games generated in 56 minutes:

Code: Select all

[] rg 10000000
   checkmate  1529145 0.152915
  fiftymoves  1933690 0.193369
insufficient  5673175 0.567318
  repetition   252856 0.0252856
   stalemate   611134 0.0611134
Average ply length: 334.401
Maximum ply length: 937
PT: 3:32:49.600
WT: 56:08.881
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Code thief

Post by sje »

mar wrote:

Code: Select all

      const ui range = -bound % bound;
      ui next = NextDwrd();
      
      while (next < range)
        next = NextDwrd();
      pick = next % bound;
}
Very nice solution for uniform distribution. Your own?
I prefer modulo-free but I find this very elegant because you can change range on the fly.
I stole it.

Search the web for "modulus bias" and you'll see similar code in many places.
hMx
Posts: 61
Joined: Wed Mar 08, 2006 9:40 pm
Location: Germany, Berlin

Re: A simple PRNG using /dev/urandom

Post by hMx »

sje wrote:Here's some C++ source code for a PRNG (pseudorandom number generator) which uses guarded access to the kernel's /dev/urandom device.
This very much looks like a RNG, without any pseudo. What do I miss? :?
matthewlai
Posts: 793
Joined: Sun Aug 03, 2014 4:48 am
Location: London, UK

Re: A simple PRNG using /dev/urandom

Post by matthewlai »

hMx wrote:
sje wrote:Here's some C++ source code for a PRNG (pseudorandom number generator) which uses guarded access to the kernel's /dev/urandom device.
This very much looks like a RNG, without any pseudo. What do I miss? :?
/dev/random and /dev/urandom are PRNG. They take environmental noise (or hardware RNG output), and do some math with it to make a pseudo-random stream with the desired distribution.
Disclosure: I work for DeepMind on the AlphaZero project, but everything I say here is personal opinion and does not reflect the views of DeepMind / Alphabet.
AlvaroBegue
Posts: 932
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: A simple PRNG using /dev/urandom

Post by AlvaroBegue »

matthewlai wrote:
hMx wrote:
sje wrote:Here's some C++ source code for a PRNG (pseudorandom number generator) which uses guarded access to the kernel's /dev/urandom device.
This very much looks like a RNG, without any pseudo. What do I miss? :?
/dev/random and /dev/urandom are PRNG. They take environmental noise (or hardware RNG output), and do some math with it to make a pseudo-random stream with the desired distribution.
Well, we are down to definitions, but I generally expect to be able to reproduce what my program did if I am careful to seed the PRNG appropriately. This won't work with /dev/urandom. For that reason alone, I would much rather use a standard PRNG without any pesky entropy getting in the way.
matthewlai
Posts: 793
Joined: Sun Aug 03, 2014 4:48 am
Location: London, UK

Re: A simple PRNG using /dev/urandom

Post by matthewlai »

AlvaroBegue wrote:
matthewlai wrote:
hMx wrote:
sje wrote:Here's some C++ source code for a PRNG (pseudorandom number generator) which uses guarded access to the kernel's /dev/urandom device.
This very much looks like a RNG, without any pseudo. What do I miss? :?
/dev/random and /dev/urandom are PRNG. They take environmental noise (or hardware RNG output), and do some math with it to make a pseudo-random stream with the desired distribution.
Well, we are down to definitions, but I generally expect to be able to reproduce what my program did if I am careful to seed the PRNG appropriately. This won't work with /dev/urandom. For that reason alone, I would much rather use a standard PRNG without any pesky entropy getting in the way.
I also almost always use pure PRNG. /dev/urandom is really only beneficial for cryptographic applications.
Disclosure: I work for DeepMind on the AlphaZero project, but everything I say here is personal opinion and does not reflect the views of DeepMind / Alphabet.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Sample timings

Post by bob »

There is another problem. /dev/random and cousins are slow. All the hysteresis data takes time to gather, and once you exhaust what is there, you get ti wait while more is collected. Better might be a simple linear congruential PRNG where you use /dev/random to seed it, then call it 10K times, and re-seed. This prevents any short cycles from showing up and beats on the kernel much less...
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Linux on older Macs

Post by bob »

matthewlai wrote:
sje wrote:Linux on older Macs

I've tried a couple different PowerPC Linux distributions on older PPC Macs. As I recall, in every case there was something broken or missing: WiFi, sleep, sound, etc. Perhaps things have improved in recent times.
That sounds a little strange, since Macs are the most common PPC computers out there (for desktop Linux at least), you would think they would be well tested.
"How much do you know about apple?" :)