|
local hash = math.random(1,9) + math.random(1,9) + math.random(1,9)
finishedhash = hash , hash , hash
print(finishedhash)
This should print a random 9 digit number, but instead it just prints any didget number ranging from 1-3 didgets and being the integers 1-9.
Makes me think it's adding the hashes instead of combining them as terms, any way to fix?
Thanks :)
[R$275] Kleptomaniac |
|
|
lol "didget". Anyways, bump. Thanks for the help in advance. :)
[R$275] Kleptomaniac |
|
|
loooking for a nice answer if any1 knows.
[R$275] Kleptomaniac |
|
LaeMVPJoin Date: 2013-06-24 Post Count: 4416 |
local finishedHash = hash + hash + hash |
|
|
Did that as well and that seems to print a three digit number always.
[R$275] Kleptomaniac |
|
ScrippaJoin Date: 2011-12-25 Post Count: 20289 |
local hash = tostring(math.random(1,9))..tostring(math.random(1,9))..tostring(math.random(1,9))
finishedhash = tonumber(hash..hash..hash)
print(finishedhash)
however if you run it you'll notice it is actually something like
987987987 since the variable hash doesn't return a new 3 digit number each time you call it, you'll have to use a function and use a returned result to solve this problem
function hash()
local hash = tostring(math.random(1,9))..tostring(math.random(1,9))..tostring(math.random(1,9))
return hash
end
finishedhash = tonumber(hash()..hash()..hash())
print(finishedhash)
|
|
|
Yea I ran into that problem and had the same solution, thanks.
:]
[R$275] Kleptomaniac |
|
|
I've never really used return, but I'm guessing this is how i'd do it?
local hash = nil
local function hash()
local hash = tostring(math.random(1,9))..tostring(math.random(1,9))..tostring(math.random(1,9))
return hash = hash
end
[R$275] Kleptomaniac |
|
|
Then combine the rest of the script into a function using the parameter of the return?
[R$0] Kleptomaniac |
|
TynezzJoin Date: 2014-04-28 Post Count: 4945 |
local hash=unpack({math.random(1,9),math.random(1,9),math.random(1,9)})
print(hash) |
|
|
That returns the repetition of the same integer
[R$275] Kleptomaniac |
|
|
bump, still looking for a viable solution.
[R$275] Kleptomaniac |
|
ScrippaJoin Date: 2011-12-25 Post Count: 20289 |
do you mean every time you start it it returns the same number?
if so, just add this on top of your script:
math.randomseed(tick())
|
|
|
I have that, and :
local hash = unpack({math.random(1,9),math.random(1,9),math.random(1,9)})
Always returns 5555555555555
[R$275] Kleptomaniac |
|
|
I meant 555
[R$275] Kleptomaniac |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
no it doesnt |
|
|
I found the problem.
[R$275] Kleptomaniac |
|