generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How to have the same thing never get selected

Previous Thread :: Next Thread 
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
15 Nov 2014 06:44 PM
math.randomseed doesn't seem to be working
Report Abuse
eLunate is not online. 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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
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
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
15 Nov 2014 07:37 PM
yes

but what's the point of math.randomseed?
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
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
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
15 Nov 2014 07:46 PM
so then why do people say

math.random(tick())
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
15 Nov 2014 07:48 PM
To ensure that the first randomly generated number isn't always the same
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
16 Nov 2014 06:34 AM
Yeah, because you are setting the seed to the same thing.
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
16 Nov 2014 02:39 PM
so if I were to put it in a loop, different things would get selected everytime?
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
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
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
16 Nov 2014 07:28 PM
That still keeps the same seed, so that still is bad.
Report Abuse
cntkillme is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
16 Nov 2014 08:02 PM
so would I do

math.randomseed(os.time())
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
16 Nov 2014 08:03 PM
math.randomseed(math.sin(tick()) * 10^9)
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
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
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
16 Nov 2014 08:07 PM
what does setting the seed even accomplish, if the random generator's gonna act the same?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
16 Nov 2014 08:21 PM
@JarodOfOrbiter: If you define "random" as "totally unpredictable", then radioactive decay is random.
Report Abuse
cntkillme is not online. 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
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image