|
| 15 Nov 2014 06:44 PM |
| math.randomseed doesn't seem to be working |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 15 Nov 2014 06:49 PM |
selected = {} for 1,10 do local n; repeat n=math.random(10) until not selected[n]; selected[n] = true; print(n); end;
You mean like that? |
|
|
| Report Abuse |
|
|
|
| 15 Nov 2014 06:52 PM |
local nums = {1,2,3,4,5,6,7,8,9,10}
local v1 = table.remove(nums, math.random(#nums)) local v2 = table.remove(nums, math.random(#nums)) local v3 = table.remove(nums, math.random(#nums)) |
|
|
| Report Abuse |
|
|
|
| 15 Nov 2014 07:37 PM |
yes
but what's the point of math.randomseed? |
|
|
| Report Abuse |
|
|
|
| 15 Nov 2014 07:41 PM |
math.random is an iterative function.
That is to say, the next value will be based off the previous value. math.randomseed just sets the initial value, for the next value to be based off. |
|
|
| Report Abuse |
|
|
|
| 15 Nov 2014 07:46 PM |
so then why do people say
math.random(tick()) |
|
|
| Report Abuse |
|
|
|
| 15 Nov 2014 07:48 PM |
| To ensure that the first randomly generated number isn't always the same |
|
|
| Report Abuse |
|
|
|
| 15 Nov 2014 11:50 PM |
| so if I were to put it in a loop, would it not select the same thing? |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 06:34 AM |
| Yeah, because you are setting the seed to the same thing. |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 02:39 PM |
| so if I were to put it in a loop, different things would get selected everytime? |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 05:11 PM |
No:
print("Seed in loop:") for i = 1, 10 do math.randomseed(7) print(math.random(10)) end print("Seed out of loop:") math.randomseed(tick() for i = 1, 10 do print(math.random(10)) end |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 07:26 PM |
what if I did this:
local amount = 3; local select = {}; for i = 1, amount do select[i] = game.Players:GetPlayers()[math.random(1, #game.Players:GetPlayers())]; math.randomseed(select[i]); end |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 07:28 PM |
| That still keeps the same seed, so that still is bad. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 16 Nov 2014 07:28 PM |
There is no point in using math.randomseed more than once (if ever). Just put it at the top of your script and you're fine. Changing the seed does not make it more random. |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 07:29 PM |
Firstly, it is entirely wrong to call math.randomseed every loop. Only do it ONCE at the TOP of the script.
Second, tick() doesn't change much, so normally the first values are similar. |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 08:02 PM |
so would I do
math.randomseed(os.time()) |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 08:03 PM |
| math.randomseed(math.sin(tick()) * 10^9) |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 08:04 PM |
"There is no point in using math.randomseed more than once (if ever)."
There are some uses for more than once, but you should always set the seed once. |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 08:07 PM |
| what does setting the seed even accomplish, if the random generator's gonna act the same? |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 08:08 PM |
Because nothing in life is random, especially computers.
You need to set the seed to get the numbers... |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 08:10 PM |
if nothing in life is truly random, then making it not pick the same thing shouldn't be truly random, right?
And, I'm trying to make it pick 3 different players, without the risk of it picking the same player in the process.
is this possible to do without randomseed? |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 08:21 PM |
| @JarodOfOrbiter: If you define "random" as "totally unpredictable", then radioactive decay is random. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 16 Nov 2014 08:24 PM |
"There are some uses for more than once, but you should always set the seed once." Stravant (or some other admin) said each script (or thread, I don't recall) gets their randomseed set by roblox. |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 08:28 PM |
@cnt, I just remembered your random thingy you showed me a few months back
I tested this with a number table, and it chose different numbers every single time, but the table wasn't read-only.
Would this always select 3 random players without the risk of selecting the same one?
selected[picked] = table.remove(game.Players:GetPlayers(), math.random(#game.Players:GetPlayers())); |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 16 Nov 2014 08:31 PM |
I do it by shuffling the table randomly instead of picking something random each time
like
local things = {"a", "b", "c", "d", "e", "f"}
function shuffle(t) for x = 1, #t, 1 do local y = math.random(#t) t[x], t[y] = t[y], t[x] end return t end
while true do shuffle(things) for _, c in next, things do print(c) end wait(3) end |
|
|
| Report Abuse |
|
|