Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 06 Aug 2016 08:50 PM |
This is a continuation from this post, https://forum.roblox.com/Forum/ShowPost.aspx?PostID=195486050
I decided to make it simpler, I'm running this code on Command Bar.
math.randomseed(tick())
local list = {} for _, v in pairs(game.ServerScriptService:GetChildren()) do table.insert(list, v.Name) end
for i = 1, 10 do print(math.random(1, #suits)) end |
|
|
| Report Abuse |
|
|
Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 06 Aug 2016 08:53 PM |
Sorry typo @ #suits. Accidentally posted the post.
Basically when you try this code, the first number it prints will be the same everytime you run the code. You can change the path, just as long as there the table list contains something. I'm currently stumped, and I don't know how to fix this. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2016 08:53 PM |
What is "suits"? Because you didn't define it here.
|
|
|
| Report Abuse |
|
|
|
| 06 Aug 2016 08:55 PM |
Fine, whatever, ninja me if you're going to. See if I care.
:(
And the first number is always the same because you are just using tick(). tick by itself doesn't change drastically enough to affect the outcome of the first one or two results for a little while. math.randomseed(tick()%1*1e7)
|
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 06 Aug 2016 09:01 PM |
This problem is explained pretty well here: http://forum.roblox.com/Forum/ShowPost.aspx?PostID=175210875&PageIndex=2 math.randomseed(tick()) is fine if you understand how it works, so when you publish your game you//players won't really run into this problem (since they won't be starting a server//reseeding a lot within a short time frame//etc.). If you don't really want to understand how it works and just want something to work use math.randomseed(tick()%1*1e7). You should only ever need to seed once.
math.randomseed(tick()%1*1e7)
local list = {} for _, v in pairs(game.ServerScriptService:GetChildren()) do table.insert(list, v.Name) end
for i = 1, 10 do print(math.random(1, #suits)) end |
|
|
| Report Abuse |
|
|
Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 06 Aug 2016 10:14 PM |
What I don't understand is when I used;
math.randomseed(tick()) print(math.random(5))
It prints random numbers from the beginning, but the moment I do something like the example above except used with this;
list = {'hi', 'hello', 'bye', 'goodbye', 'wot'} math.randomseed(tick()) print(math.random(#list))
It doesn't work like the first example I showed, instead it prints the number 1. Why do these two cases give different results, when just looking at it, it looks similar. |
|
|
| Report Abuse |
|
|