Function MATH.random() different than random() ?

Hi,
I don’t know if it’s luck but when I use the function
math.randomseed(Time.Now());
random(1,X)

It seems every time I restart the game it gives the same number in the same order.

If I use
math.randomseed(Time.Now());
math.random(1,X)
Then it seems to give real random number.
So obviously I will use math.random(1,X).

Do you know why ?
Thanks

I’m like 90% sure random(X,Y) is not a function of the base library for Lua. math.random(X,Y) is what comes with Lua.

In any event, you may wish to use os.time() rather than Time.Now(), even though os.time() is only measured in seconds.

But the devs are using Time.Now(), is it in hours ?!!

I have no idea what it’s in because it’s nonstandard. :stuck_out_tongue: os.time() is standard C Lua.

there is no os.time() for grim dawn thats why there is Time.Now()

I just tested the 2, its both random, so I guess its just pure luck for you :smiley:

oh and
random = math.random

Executed at the same moment :
Time.now gives 7258002
os.time() gives 1468959815

hmm, why is os.time() working for you :smiley: it just crashes my script

I just tried os.time() inside a print :
print(“TimeNow=”,Time.Now(),“os.time()=”,os.time())
I didn’t try using it for randomseed.
Does it work for you ?

nope, even tried tostring(os.time()) and nothing :smiley:
and doesnt matter… Time.Now() is working and the function I made for random numbers and chances is using math.random…

It’'s definitively NOT random !
I tried this :

math.randomseed(Time.Now());
print(“random1=”,random(1,10000000),“random2=”,math.random(1,10000000))

I exectuted it 3 times after reloading the session and everytime random1 gives the same numbers in the same order when random2 really gives random numbers !

You have to reset the seed before each call to random in other languages. So the second call is the only one generating a non seeded random number.

But that also suggests that TimeNow keeps returning the same number if random1 is always the same on subsequent calls.

I don’t understand.
Isn’t math.randomseed(Time.Now()); supposed to reset the seeds ?
that’s what the devs use.

What I understand is that if I use MATH.random(1,X) it’s really random and not if I use random(1,X) in the same configuration.

since these are results from grim dawn hook Im just gonna go with a grim dawn hook issue :smiley:
did you try it with UI.Notify? could also be the reason why os.time() is working for you :slight_smile:

and randomseed resets the numbers, using it once is fine, without using it you would get the same numbers in the same order same after setting a new seed [with the same value], so everytime you change the seed you change the sequence and since Time.Now() always returns a different number with a new session it wont have the same sequence

Thank you for your help.
I had an issue with my computer clock a few weeks ago, but it has been resolved since, so I don’t think it’s related.
Anyways, I will keep usin Time.Now as it seems to be working but I will now use math.random as I am certain it is working and really random and doesn’t need tricks to be working.

huh, what ? You should only seed once, otherwise you just mess up the RNG algorithm as you cut every sequence short and just make the whole thing less random than it otherwise would be…

Yeah, the post I replied to did not have the image yet, not really sure what I thought I read, but I was trying to explain that to get the exact same random number each time, you have to set the seed, with the same seed, before each random call.

But looking at the numbers in the image, I think I misunderstood.

yeah, just dont set a new seed for actions that occure more than once a second, I removed alot of the new seeds - even used it for loot, and of course it would just drop the same item 5 times because the new seed would always start the new same sequence :smiley:
I think I only have a new seed when the world is loaded and a new portal opens.