SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 03/08/2019, 03:53 PM   #1
Manuel78
Little Clucker
 
Join Date: Jul 2017
Posts: 8
Reputation: 0
Default Random numbers

Are random numbers in pawno really random? I read somewhere on this forum that pawno has congruential pseudo-random number generator with a range and a period of 231. So can someone explain how does it actually work? I'm fascinated with things like that and I can't find meaningfull results on ******.
Manuel78 is offline   Reply With Quote
Old 03/08/2019, 05:47 PM   #2
dugi
Beta Tester
 
Join Date: Jun 2007
Location: Poland
Posts: 2,305
Reputation: 841
Default Re: Random numbers

https://github.com/pawn-lang/compile.../pawn-lang.pdf check page 126

Random number generators in programming languages are pseudo-random it's the same in case of Pawn(not Pawno which is the editor).

https://www.cs.utah.edu/~germain/PPS...m_numbers.html
dugi is offline   Reply With Quote
Old 03/08/2019, 06:46 PM   #3
Manuel78
Little Clucker
 
Join Date: Jul 2017
Posts: 8
Reputation: 0
Default Re: Random numbers

So based on this it's not random, now my question is can you guess a sequence of numbers somehow if you know how random() function looks like?
Manuel78 is offline   Reply With Quote
Old 03/08/2019, 08:42 PM   #4
Freaksken
Gangsta
 
Freaksken's Avatar
 
Join Date: Mar 2009
Location: Belgium
Posts: 501
Reputation: 367
Default Re: Random numbers

Random number generators often work with a seed, which is a number that is used in the calculation to provide the random numbers. When the same seed is given, you will get the exact same sequence of random numbers. In most languages, you can manually set that seed. Pawn however, doesn't seem to have a way of explicitely setting the seed, so most likely the system's clock time is used implicitely.
__________________
Always keep in mind that a lot of people are active on this forum in their spare time.
They are sacrificing time they could easily spend on things they would rather do, to help you instead.


[Include] FCNPC A.I. - [Tutorial] Speedometer - [WIP] Single-player-like co-op mission - [Other] List of all my work
Freaksken is offline   Reply With Quote
Old 03/08/2019, 09:43 PM   #5
Manuel78
Little Clucker
 
Join Date: Jul 2017
Posts: 8
Reputation: 0
Default Re: Random numbers

So players shouldn't be able to predict numbers in lotto for example.
Ok
Manuel78 is offline   Reply With Quote
Old 16/08/2019, 06:29 PM   #6
CheezIt
Big Clucker
 
CheezIt's Avatar
 
Join Date: Apr 2017
Posts: 182
Reputation: 17
Default Re: Random numbers

Quote:
Originally Posted by Manuel78 View Post
So players shouldn't be able to predict numbers in lotto for example.
Ok
Most likely, not
__________________
I'd like to bring back my old CNR server that was created from scratch & hosted years ago. I'll host & update everything (including the website & forum). You would pay for hosted tab and help manage the community. PM me if you're interested!
CheezIt is offline   Reply With Quote
Old 31/08/2019, 07:51 AM   #7
GTLS
High-roller
 
GTLS's Avatar
 
Join Date: Aug 2014
Location: India
Posts: 1,047
Reputation: 115
Default Re: Random numbers

The current random number logic is BY FAR the most accurate than in the past. Although, you can create your own algorithm using your formula to try to create a better random generator but the odds are you will end up with more predictable algorithm.

https://en.wikipedia.org/wiki/Pseudo...mber_generator - Read here

current PRNG method is really good. You can test it easily. You can Generate 200-300 or more values using any algorithm, and divide the numbers's range into half. (For eg, if you created random numbers between 0 to 1, use 0.5 as mid point). Now, count how many random numbers are generated less than 0.5 and more than 0.5. If they are close to 50%, it means algorithm is almost perfect.
__________________

I don't help for rep. I help cuz I was helped in the past.


Retired from SAMP Scene. Might open SAMP Forums once in a while.

Some treats for ya. Click em
Basic House System
Simple Speedo
Base Login/Register Script

GTLS is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random between 4 numbers Zloto Scripting Help 3 05/05/2015 10:36 PM
Random numbers RedCode Scripting Help 7 16/03/2015 12:57 AM
Random Numbers ZBits Scripting Help 3 17/01/2014 03:43 AM
Random Numbers Zex Tan Scripting Help 6 19/01/2013 01:54 AM
Random numbers Jimbo01 Help Archive 2 01/02/2011 08:45 PM


All times are GMT. The time now is 10:32 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.