Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1366136 Posts in 64012 Topics- by 55898 Members - Latest Member: obemef

September 17, 2019, 09:11:27 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)RNG or PRNG?
Pages: [1]
Print
Author Topic: RNG or PRNG?  (Read 1060 times)
SteveYouNeed
Level 0
*


View Profile
« on: September 17, 2018, 07:41:49 AM »

Hello guys, i’m here for a quick question

disclaimer: it could sound stupid to more acknowledged people  Tongue Embarrassed

About simple video games programming, I’m trying to make my own video slot machine. I saw on several links first thing I need to do is to find a reliable random number generator and here my first one question: I saw on Wikipedia https://en.wikipedia.org/wiki/Random_number_generation#%22True%22_vs._pseudo-random_numbers differences between “true” RNG and “pseudo” RNG; which one of these two should I rely on in my case? To be honest I haven’t even understood the difference clearly so..

Second doubt I have is about which RNG I should choose, I saw there are many based on different sources; on this link [suspicious link removed] there are steps about how a slot is made, info about RNG, but nothing on which one and where to find it.

Can someone help me out here as well?

lots of thanks  Smiley Smiley
« Last Edit: July 23, 2019, 06:39:25 AM by ThemsAllTook » Logged
Schoq
Level 10
*****


♡∞


View Profile WWW
« Reply #1 on: September 17, 2018, 08:20:29 AM »

I don't think you can generate "true" random numbers without access to special hardware which bases it on some external random factor like background radiation (you might be able to find some online solution for this though). Anyway this should probably go in Technical.
« Last Edit: September 17, 2018, 11:07:33 AM by Schoq » Logged

♡ ♥ make games, not money ♥ ♡
Crimsontide
Level 5
*****


View Profile
« Reply #2 on: September 17, 2018, 09:01:08 AM »

PRNGs with a good seed value are fine for games, you only need *TRUE* RNG for cryptography.

Use something like a 32 or 64 bit Mersenne Twister (there are implementations in dozens of languages, for example C++ has it as part of their standard library).  Just avoid LCGs, as they are crap.

For a good seed you can use, the number of nanoseconds since 1970 (something like std::chrono::high_resolution_clock, QueryPerformanceTimer).  If you like assembly the number of ticks from any CPU core will be essentially random.  Or you can sample from a webcam or mic, just use the low bits since they are mostly noise.
Logged
Superb Joe
Level 10
*****



View Profile
« Reply #3 on: September 17, 2018, 10:24:40 AM »

do NOT use your low bits on web cam unless the other party is an adult and consents to such behaviour
Logged
Crimsontide
Level 5
*****


View Profile
« Reply #4 on: September 17, 2018, 10:37:37 AM »

do NOT use your low bits on web cam unless the other party is an adult and consents to such behaviour

Hmmm... I hadn't thought of that.  Can that really lead to legal repercussions?
Logged
Daid
Level 2
**



View Profile
« Reply #5 on: September 18, 2018, 12:07:57 PM »

Difference between "true" RNG and pseudo RNG, is that the pseudo version can be predicted/influenced by the user. This can also be an advantage, a pseudo RNG will produce the same set of numbers every single run if you start off with the same seed.

For games, generally, a pseudo RNG will do, seed it with a timestamp, and it's hard to predict.

If you need RNG that is not predictable, there is /dev/random in linux (or /dev/urandom) and https://docs.microsoft.com/nl-nl/windows/desktop/api/ntsecapi/nf-ntsecapi-rtlgenrandom for windows.
But these are generally needed for security, not for games. And the "pool" of random numbers generally isn't very big.

I don't know for Windows, but for Linux, that gathers some randomness from timing in network traffic and keystrokes. As well as RNG hardware if it's available.



Anyhow, for games, unless real money is involved, the psuedo RNG is fine. Timestamp as seed provides more then enough feel of randomness for the players. (Also note, that random does not always feel very fair for players. As a RNG might give a lose streak of 100, even if the chance is 1 out of 10. Recently read a good article about it, but cannot find it)
Logged

Software engineer by trade. Game development by hobby.
SteveYouNeed
Level 0
*


View Profile
« Reply #6 on: September 25, 2018, 01:51:19 AM »

Thanks Smiley
Logged
Ordnas
Level 6
*



View Profile WWW
« Reply #7 on: September 26, 2018, 08:20:24 AM »

I used a Mersenne Twister for my Slot Machine game at home.
Logged

Devlogs:

fluffrabbit
Level 2
**



View Profile WWW
« Reply #8 on: July 23, 2019, 02:56:43 AM »

I know the question is already answered, but someone bumped the thread so I figured I might as well give my 2 cents.

AFAIK, Mersenne Twister is designed to be "uniform" rather than cryptographically secure or close to nature. For games it's great because if the statistics say that something is supposed to happen a certain percent of the time, it probably will. Contrast this with the typical rand() % some_number where the output is all over the place and "random" in more of a "lol so random" way (perceptually buggy) as opposed to evenly distributed.
« Last Edit: July 23, 2019, 03:03:23 AM by fluffrabbit » Logged

Silbereisen
Overlord
Administrator
Level 10
******


eurovision winner 2014


View Profile
« Reply #9 on: July 23, 2019, 04:00:37 AM »

"true" rng is much more difficult to implement because as others said, it requires hardware that not all players (or platforms if you're going multiplat) may have. also the difference between true rng and prng, given that you're using a good prng, is gonna be negligible to everyone except speedrunners.
Logged
fluffrabbit
Level 2
**



View Profile WWW
« Reply #10 on: July 23, 2019, 01:43:14 PM »

As people previously stated, you can get a "true" source of randomness (more accurately called a source of entropy) from webcam and microphone, maybe also network. PRNGs serve to frombulate the entropy into a distribution, and your choice of PRNG algorithm will determine the fine details of said distribution. It's worth researching the different options.

For instance, is your range 0-1 inclusive, or 0-0.9999999? When you graph it, does it look like spikes or another shape? How well does the algorithm perform for different tasks? In games of chance, the randomness is the whole point, so I would pay attention to these things.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic