Robin Andersson
Robin Andersson

Reputation: 5380

Is there any non-global seeded random in LUA?

Is there any non-global method of generating a seeded random number in LUA?

The function math.randomseed() sets the seed for the whole application (which is less than ideal) and if the code is executed async there is a risk that other parts of the application "steals" numbers from the sequence.

One good example from C# is the Random class where you can initialize a Random instance with a seeded number rather than setting the seed for the whole application: https://learn.microsoft.com/en-us/dotnet/api/system.random.-ctor?view=netcore-3.1

Upvotes: 1

Views: 139

Answers (2)

lhf
lhf

Reputation: 72362

My lrandom library provides independent streams of random numbers. It can also reset and clone streams.

lrandom is a C library. For a plain Lua solution, see mt19937ar-lua.

Upvotes: 2

DarkWiiPlayer
DarkWiiPlayer

Reputation: 7064

No.

You might find some third-party library that does this though.

Upvotes: 4

Related Questions