SRB2 Message Board  

Go Back   SRB2 Message Board > Sonic Robo Blast 2 > Releases > Lua

Reply
 
Thread Tools
SeedRng: seedable pseudorandom number generator Details »»
SeedRng: seedable pseudorandom number generator
Version: r2, by FSX (cheap spirit) FSX is offline
Developer Last Online: Aug 2017

Category: Version: SRB2 Rating: (1 votes - 3.00 average)
Released: 12-22-2016 Last Update: Never Installs: 0
Scripts Re-Useable Content

SeedRng is an alternative RNG implementation that grew out of a different project I was working on. It might be better for some uses, maybe.

How to Use
One global function is created: A_SeedRng_Get(). This function returns a table that contains all of the functions SeedRng includes (which is what SeedRng means in the following function definitions).
SeedRng.Create(net, <seed,...>): Creates a state, which is needed for all other functions. If net is true, this state is network-synchronized. If net is false, it is not. seed is 0-4 numbers, which are used to fill the state. Any missing numbers are filled in. It returns the state, which you should treat as an opaque object (in reality, if networked it is a number and if not it is a table).
SeedRng.Get32(state), SeedRng.GetFixed(state), SeedRng.GetByte(state), SeedRng.GetSignedByte(state), SeedRng.GetBool(state): These all take one argument, a state, and return the type of value their name indicates.
SeedRng.GetChance(state, chance): Basically the same as P_RandomChance().
SeedRng.GetKey(state, limit): Returns a random integer between 0 and limit-1. limit can be as large as INT32_MAX.
SeedRng.GetRange(state, lower, upper): Returns a random integer between lower and upper, as long as they are within INT32_MAX-1 of each other. If not, an error occurs.
SeedRng.Destroy(state): Destroys a state. Trying to use it again after this will cause some sort of error. You should do this whenever you are done with a state (but for non-networked ones it doesn't really matter).

Commands
If you use this script, you should probably remove the commands.
They are not intended for any use but testing.
srngtest_init: Creates a state for the out commands.
srngtest_netinit: Creates a networked state for the out commands. There's no way to destroy it later, so this one really shouldn't be used while you're doing anything else.
srngtest_out32: Runs Get32 as listed above on the state made by the init commands and then prints it with some other nonsense on the console.
srngtest_out1k: Similar, except it tests GetKey instead.
srngtest_demo: Sets up the demonstration mode shown in the screenshots.

Network-synchronized vs. unsynchronized states
Network-synchronized states must be used for any behavior that must be the same on all instances of the game, but take up space in $$$.sav. For that reason, if an effect is purely visual, you should probably use an unsynchronized state.
SeedRng r1 lets you use network-synchronized states from HUD code. This is unsafe and should not be done. If using r1a, you will get an error if you do this. And no, it is never a good idea to do: it will likely result in desyncing.

Acknowledgements can be found in the source code.

Possible issues
I am somewhat uncertain about the quality of the left and right shift functions, but not very.

Changelog
r2
  • More comprehensive HUD checks.
  • Better seed checking.
  • Some fixes to the demo functions.
r1a
  • Rotate function reimplemented to not call any functions
  • HUD checks implemented, preventing unsafe function calls during HUD drawing.
r1
Initial release.

Planned updates

None as of right now. Any bugs will of course be fixed, but I don't know of any right now.

Download Now

File Type: lua SeedRng-r1a.lua (8.4 KB, 64 views)
File Type: zip SeedRngr2.zip (3.1 KB, 39 views)

Screenshots

Click image for larger version

Name:	srng_still.png
Views:	196
Size:	60.9 KB
ID:	9313   Click image for larger version

Name:	srng_motion.gif
Views:	236
Size:	1.41 MB
ID:	9314  

Show Your Support

  • The author of this addon has given explicit permission for its content to be re-used and/or reproduced.

Comments
Old 01-16-2017   #2
FuriousFox
AKA FuriousFox
Developer
 
FuriousFox's Avatar
Default

Sorry for letting this sit here for so long, we weren't really sure what to do to judge this. I tested the included console commands and they seem to work as expected, so I'm just going to go ahead and pass this through.

Welcome to Releases!
FuriousFox is offline   Reply With Quote
Old 08-08-2017   #3
FSX
cheap spirit
Default

r2 is now available. This improves the seed extension code and provides more robust checking to ensure networked states aren't modified where they shouldn't be.

Last edited by FSX; 08-08-2017 at 05:00 PM.
FSX is offline   Reply With Quote
Reply

Thread Tools

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

Forum Jump


All times are GMT. The time now is 02:09 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.