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
|
  |
| 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
|
  |
| Joined: 16 Nov 2013 |
| Total Posts: 74 |
|
|
| 17 Apr 2016 10:36 PM |
| i dont understand, what do you mean? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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 |
|
|