local t = {1, 2, 3, 4}
local r = Random.new(101)
r:Shuffle(t)
print(t) -- Gives a result of {1, 2, 3, 4} always
To fix it, we must avoid specifying a seed, or use the generator once:
local t = {1, 2, 3, 4}
local r = Random.new(101)
r:NextNumber()
r:Shuffle(t)
print(t) -- Gives a correctly shuffled result.
2 Likes
Using a seed of 102
gives 4, 2, 3, 1
. It seems like 101
is just a Random seed that simply doesn’t Shuffle the array.
3 Likes
WheretIB
(WheretIB)
July 8, 2024, 11:05am
#3
{1, 2, 3, 4}
is one of the valid shuffles of the {1, 2, 3, 4}
array which happens to be selected with that seed value.
6 Likes
Oh oops! My bad… I must have hallucinated checking other seeds haha
2 Likes
debugMage
(debugMage)
July 8, 2024, 10:37pm
#5
i feel like its kind of misleading for :shuffle() to not actually shuffle though.
may need to be a feature request!
2 Likes
Tomi1231
(Chilly28)
July 8, 2024, 10:47pm
#6
It’s simply how randomness works. You have a 1/24 (?) chance for the table to be shuffled in that particular order. It shuffled, but it returned the same order, out of pure luck (if you can call it luck. It’s pseudo random, so it’s predictable randomness)
5 Likes
system
(system)
Closed
July 22, 2024, 10:48pm
#7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.