18 posts
Posted 11 December 2012 - 12:40 PM
Is there a way to implant a RNG into a program using lua?ive looked but i cant figure out a way.Thank you in advance.This is going to the game im programming in CC.
180 posts
Posted 11 December 2012 - 01:43 PM
That would be the math.random() command.
With no arguments it returns a floating point value between 0 and 1
Or you can call it as math.random(10) to generate a random integer number between 1 and 10
Before using it, you will want to set the RNG seed to something as unpredictable as possible.
To do so use math.randomseed(int)
Normally in CC I do that with math.randomseed(os.time())
2217 posts
Location
3232235883
Posted 11 December 2012 - 01:53 PM
usage:
math.random([m[,n]])
When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n].
1619 posts
Posted 11 December 2012 - 01:55 PM
usage:
math.random([m[,n]])
When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n].
Off-topic: Umm… Pixel? Your location says "cruor." One quick question: WTF?!
56 posts
Posted 11 December 2012 - 03:09 PM
Like this?
local t = {1, 2, 3, 4, 5}
a = math.random(1, #t)
print(a)
1190 posts
Location
RHIT
Posted 11 December 2012 - 03:18 PM
Like this?
local t = {1, 2, 3, 4, 5}
a = math.random(1, #t)
print(a)
Yup that would work if you're trying to get a random index from the table.
2217 posts
Location
3232235883
Posted 11 December 2012 - 03:21 PM
Like this?
local t = {1, 2, 3, 4, 5}
a = math.random(1, #t)
print(a)
sould be
local t = {1, 2, 3, 4, 5}
local a = t[math.random(1, #t)]
print(a)
if you want to get a random thing from the table