RNG

Started by
3 comments, last by frob 5 years, 7 months ago

Hi guys i'm new here, i really hope my question won't sound utterly stupid..

I'd like to know whether it's better to use a PRNG or a regular RNG, if you are trying to program your own video slot machine. Actually i don't even have clearly understood the difference between the two =D

2nd question is: which developer i should rely on? I'm following this guide, they talk about RNG but not which one or where to find it.

Thank you in advance :)

Advertisement
1 hour ago, lilbump said:

program your own video slot machine

Are we talking something which could be used on a gambling site, involving real money?

Or just a normal "game" slot machine, no actual money goes in/out of the system?

 

This is a very important question to answer before proceeding.

Hello to all my stalkers.

thanks for answering. I'm not using real money: as a developer, I recently run into this and it was just a thing that I wanted to try for personal fun on the evening, nothing more than that :)

16 hours ago, lilbump said:

a PRNG or a regular RNG ... Actually i don't even have clearly understood the difference between the two =D

Whether you call them "random" or "pseudo-random" depends on who you talk with.  For most people there is no difference, but since you mentioned slot machines, that's one of the few exceptions where there is a difference.

Computer algorithms are deterministic and will generate the same numbers if you give them the same initial conditions. The number might be unpredictable as far as humans can see, but an attacker who can peek at the memory of the computer can know exactly what the next value will be. Someone who watches the number generator long enough can also (theoretically) determine what the internal state of the generator is, so they can also predict what the next value will be.

Sometimes that ability to predict the number is a problem. Gambling has the obvious problem of cheaters. Encryption is a problem if you can predict what the encryption key will be. Some algorithms have patterns that appear with number generation algorithms, meaning some number generators can't be used. Sometimes the patterns are incredibly complex and will pass statistical tests, but they'll still exist in a way that breaks the intended uses.

That's why there was the question of if your slot machines were to involve real money.

In those cases people will rely on physical sources that are believed to be random. One source is nuclear decay detected by a Geiger counter. Another source is a radio station tuned to static noise. Another source is computer transistors and resistors highly amplified to the point that individual electrons bump the signal around.  Physicists and engineers can build hardware that they believe is a completely unpredictable source of data, but even that is a topic for debate and quickly becomes a philosophy question about what it means to be random.

Some sources of numbers are somewhere in between. There are algorithms that detect timings of real-world things like the timing of keystrokes or the timings of hard drive movements and run those through randomization algorithms. SGI used to have a set of lava lamps and web cameras, the resulting video streams of the lava lamps could be fed into a random number generator.

 

16 hours ago, lilbump said:

which developer i should rely on? I'm following this guide, they talk about RNG but not which one or where to find it.

Most of the time (except for real-money regulated gambling, encryption, etc) you can use any source of random numbers you want. 

Programming languages tend to have at least one random number generator as part of their standard libraries.  The C++ standard library currently requires a minimum of three random number generation algorithms with nine different number generation configurations; once you've generated the number, the library has 21 different distribution curves you can apply such as various bell-shaped curves, S-shaped curves, exponential curves, evenly-distributed values across a range, etc.  C++ compiler vendors are free to provide more of them if they wish. 

If the number generators built into the programming languages aren't enough, there are plenty of web sites devoted to the mathematics of number generation. 

Exactly how hard-core you want to get depends on how you want to use the library and how free of bias it needs to be.  It takes a lot of effort to ensure a random number remains random.  For example, if I generate a random 32-bit value I have something in the range of 0-4294967295. We'll call that number rand.  If I decide that I really want a single digit number, I might use the result of  rand % 10. While that does give me a value from 0-9, they are not perfectly distributed even if the original 32-bit value was perfectly distributed. You'll notice the range doesn't end in a zero and isn't a perfect multiple, so the numbers 0-5 will have a slightly higher chance to appear than the numbers 6-9.  If you're doing something like spawning monsters in a game the small bias doesn't matter.  If you're encrypting secrets that need to be safe from international governments or picking lottery numbers worth millions of dollars, that bias can be a problem.

This topic is closed to new replies.

Advertisement