This might just be the stupidest question to ever be asked on this site, but I don’t know please help
I have a code that generates a random number between 0 and 1 using Random.new():NextInteger()
If its “0” it adds 1 to a variable called "A", if its “1” it adds 1 to a variable called "B"
Then I an event to print A and B
Here is the thing, I thought if there was a 50/50 chance, the 2 numbers would be extremely close, and although they are, they’re not as close as I thought they would be after a good amount of tests
Am I doing something wrong or Is that just how random stats work?
Please excuse my ignorance, I was never a math person.
Interesting… by the way, Should i use math.random or Random.new()
I’ve read alot and some people say math.random is faster, some other people say Random.new() is more random, and some other people say they’re the same
math.random and other random functions use an algorithm that kind of “fakes” randomness, that is why you can give it a seed and get the same numbers every time, because it’s not true randomness. However, don’t ask me how those algorithms work lol
The way these work might be the reason why they aren’t as close. Or it could just be normal, the difference isn’t huge, and the relative gap between the two seems to gets lower the higher the numbers are (A-B)/(The bigger one, maybe)
There’s this video from Tom Scott which shows a wall of lava lamps that are used to get true randomness, it’s quite interesting
Random.new() is a lot more feature rich, and the number size limit is also much higher (idk if the limit for math.random() is 32 bits numbers, but the limit isn’t too hard to reach)
math.random() is more convenient so that’s the one I use more often
I’ll keep that in mind, btw I have a question, If i was making a percentage possibiltiy system, Should I randomly generate numbers from 1 to 100, or 0 to 100? I see people do 0 to 100, but if you count 0 as a number that means it can generate 101 different numbers, wouldn’t that make it 101%?
If you do it from 1 to 100, then you cannot get under 1%, so probably from 0 to 100. Otherwise there’s also 0 to 99 I guess…
And yes 0 to 100 is 101 numbers, things can be weird sometimes, it’s likes rgb, you got values from 0 to 255, which is 256 numbers, but if you want to make a increment thing, you have to do jumps of 15 instead of 16.
I would say either generate a random integer between 1 and 100 or a random float between 0 and 1. If an item’s chance is zero percent, then its logical for it to be impossible to get. If the chances as percentages are not necessarily integers, just choose a float instead of an integer.