Stormworks: Build and Rescue

Stormworks: Build and Rescue

Not enough ratings
Random Number Generator
   
Award
Favorite
Favorited
Unfavorite
Vehicles: Air, Sea, Creative, Land
Tags: v1.0.26
File Size
Posted
443.245 KB
23 Dec, 2020 @ 2:48pm
1 Change Note ( view )

Subscribe to download
Random Number Generator

In 2 collections by katstel
kat's microprocessors
24 items
katstel
52 items
Description
Random Number Generator
How to use
This is a microprocessor that generates a random number between 1 and 100 (or within a set bound) at the press of a button. It is very easy to set up. Simply connect a push button to the main input. Each time you press this button, a new random number will be drawn from the system into the numerical output. The threshold of numbers generated can be selected in the property menu with the sliders of minimum and maximum value.
=> NOTE: when selecting the minimum and maximum threshold, do not put the min threshold larger than the max threshold. It will not work properly and a tooltip warning will appear on the microcontroller.
=> NOTE: only use a push input or it will not function properly

How does it work?
There are a series of PID controllers continuously oscillating between a set positive and negative value, and a function which gets the ”average” across all these controllers. By isolating the string of decimal values we get a very precise number which is continuously changing so quickly it is perceived to be random. Whenever the user presses the “Retrieve number” button, it pulls a number (which number is multiplied from the “random” string of decimal values and rounded to form an integer) and puts it through a memory register to save it in the system.
Because there are multiple PID controllers running at once, the “random” value constantly cycles up and down randomly between 0.01 and 9.99 so there isn’t exactly a “pattern” or “cycle” to it. This adds an extra factor of randomness to the system. However as an extra “failsafe” to ensure maximum randomness there is a very very short timer on the input, which does not permit a value to be sent through as long as the user is still pressing the button. This allows only one value to be sent on each input.

Probabilities
Now, that being said, there is a slightly higher probability you will receive certain numbers compared to others. While it is still possible, you are slightly less likely to get the exact value of the minimum or maximum bound itself because these can only be rounded one way to be output, contrary to the rest of the values which can be output by rounding up or down. From a non-mathematical/statistical point of view it is as random as random can get, and that’s all you need to worry about. It is actually possible to receive every single whole number between 1 and 100 and i have tested this to be true. So please don’t come to me and fuss about how some numbers don’t appear. It’s random and will not be the same every time.

Fair Use
Please give credit when used on your creations. Thanks
9 Comments
katstel  [author] 9 Aug, 2021 @ 4:59pm 
@aladdinno YT
I have thoroughly tested it prior to posting, so if it doesn't work then there is mostly likely a update /glitch in the game that broke it. I will re-test it and see if I can find any fault on latest version of the game.
Aladdinno 9 Aug, 2021 @ 6:47am 
it doesnt works
TheSavageProdigy 6 Feb, 2021 @ 7:09pm 
How do people like you get unnoticed when you make things like this holy crap.
katstel  [author] 25 Jan, 2021 @ 3:48pm 
im not good with lua, and i dont know if these commands are compatible with the stormworks API. I looked into that and figured it would be easier to do this than figure out a lua solution for it.
Yan Kerschen 23 Jan, 2021 @ 11:35am 
good work but next time use math.random in lua
thatcoolcat1 26 Dec, 2020 @ 7:34am 
good work :steamthumbsup:
katstel  [author] 25 Dec, 2020 @ 11:49am 
thx ^^
Orca 24 Dec, 2020 @ 6:27pm 
nice
sundermann99 23 Dec, 2020 @ 6:44pm 
ahh haa, finnaly