Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I improve my random script?

Asked by
neoG457 315 Moderation Voter
9 years ago
storage = game.ReplicatedStorage
backpack = game.Players.LocalPlayer.Backpack
math.randomseed(tick())

storage["Kagune" .. tostring(math.random(8))]:clone().Parent = backpack

This local script in starterpack chooses a random local script from Replicated Storage and clones it into the players backpack however it seems to be choosing the same random local scripts for everyone. Is there anyway to improve this script to make the randomisation better?

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

If the script is given to everyone at the same time, they're all going to be seeded with the same tick. If they're on the same kind of computer in the same time zone, that means the numbers you get out of math.random are going to be the same.


Just don't see seed -- you don't need to.


Purely random numbers are unpredictable. Most of the time, there will be repeats between items -- if there weren't, you don't have a very good random number generator.

If you don't want it to actually be random, e.g., you don't want many/any repeats, you need to actually write code to make that happen -- a good random number generator won't give you that.

Ad

Answer this question