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 » Scripters
Home Search
 

make math.random not select same number?

Previous Thread :: Next Thread 
2e9 is not online. 2e9
Joined: 16 Nov 2013
Total Posts: 74
17 Apr 2016 10:31 PM
for example,

while true do
wait(1)
a = math.random(1,10)
print(a)


how to make it so that the same number doesnt show ever again until playr leaves?
Report Abuse
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
17 Apr 2016 10:35 PM
In these situations, use math.randomseed(tick()) before calling any random function.
Report Abuse
2e9 is not online. 2e9
Joined: 16 Nov 2013
Total Posts: 74
17 Apr 2016 10:36 PM
i dont understand, what do you mean?
Report Abuse
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
17 Apr 2016 10:42 PM
Actually, I think I misread your post, so ignore what I just wrote.
Report Abuse
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
17 Apr 2016 11:00 PM
Hey, I'm back. So, I saw your previous post and nox7 had posted a solution that I decided to improve upon.

random() takes in your minimum value, maximum value, and table that will store all previous numbers counted.

random() returns the random number and the list.

Once random() has counted all the available numbers, it will return nil.

This way, you can know when all the numbers have been found safely and stop the repeat loop, saving resources.
-------------------------------------
local function random(min, max, list)
local list = list or {};

local function notIn(t, val)
if (t[val]) then
return false;
else
return true;
end
end

local number;
repeat
if (#list == max) then
return nil;
end
number = math.random(min, max)
until notIn(list, number);

list[number] = true;
return number, list;
end
----------
-- Main
----------

local list = {}
local min, max = 0, 10;
local number;

while true do
wait(.2)
number, list = random(0, 10, list);

if not (number) then
break
end

print(number)
end

print("All numbers counted!")
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
17 Apr 2016 11:03 PM
local nums = {}

prevNum = function(x)
for i,v in next, nums do
if x == v then
return true
end
end
end

while wait(1) do
local x = math.random(1,10)
while prevNum(x) do
x = math.random(1,10)
wait()
end
table.insert(nums,x)
print(x)
end


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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