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
 

Re: Make a random value picker not pick same number twice?

Previous Thread :: Next Thread 
2e9 is not online. 2e9
Joined: 16 Nov 2013
Total Posts: 74
17 Apr 2016 10:25 PM
i tried alot of different ways, and scripts, and none work. Can someone please help me out? i just need it to not pick the same number again.
Report Abuse
nox7 is not online. nox7
Joined: 29 Aug 2008
Total Posts: 27467
17 Apr 2016 10:31 PM
I think the best way is to make your own function that uses math.random(), but also checks a table and repeats it if the number is already chosen. Like this:

local function mathRandom(min, max, alreadyChosenList)
local chosen
local alreadyChosen
alreadyChosenList = alreadyChosenList or {}
local function isInList(tab, val)
local inList = false
for i,v in pairs(tab) do
if (v == val) then
inList = true
break
end
end
return inList
end
repeat
chosen = math.random(min, max)
until (not isInList(chosen, alreadyChosenList)
table.insert(alreadyChosenList, chosen)
return chosen, alreadyChosenList
end


local list
for i = 1, 5 do
local num
num,list = mathRandom(1,5)
print(num)
end

-----

This will never pick the same number twice.
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
17 Apr 2016 10:54 PM
That code will also only pick 5 numbers. Then the sixth time you call it, the code will drop into an infinite loop.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
17 Apr 2016 11:02 PM
Lol. Literally everything nox had in under 20 lines.

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
cntkillme1 is not online. cntkillme1
Joined: 16 Feb 2012
Total Posts: 592
17 Apr 2016 11:08 PM
[ Content Deleted ]
Report Abuse
XhappysmileX is not online. XhappysmileX
Joined: 22 Feb 2009
Total Posts: 124
18 Apr 2016 07:14 AM
"what awful solutions."

So provide better ones? Don't prove just how useless you are so easily.
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