I'm trying to make a small game, and I need some random integers. Like, a random integer between 1 and 6, for example. Or between 150 and 550.
How would I go about doing this?
Random number?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Random number?
If you call math.random too often you better call math.randomseed(os.time()) before of math.random...
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Random number?
No, don't do that. The default love.run already does that, and the random number generated only needs to be seeded once.batatinha wrote:If you call math.random too often you better call math.randomseed(os.time()) before of math.random...
Help us help you: attach a .love.
Re: Random number?
No, actually it's a good practice to randomize it time to time. If you sure that between two randomizations the amount of math.random calls is really random (that is does not depends on random function but rather on random events) you can use math.random as a random seed. I.e. you can call randomization every 10 seconds, while amount of random usage in between is really random since it would depend on user interaction and in-game events going on, and framerate isn't entirely stable which adds up to total randomness even if every frame is precisely the same.
Re: Random number?
Why?raidho36 wrote:No, actually it's a good practice to randomize it time to time.
And it's just a game after all. It's not a case of security.
I think things like the new random generator in 0.9.0 (love.math.random), can give better results than resetting the random seed.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Random number?
I've never heard anyone claim that before. I've seem people do it, but they all had no clue how RNGs work.raidho36 wrote:No, actually it's a good practice to randomize it time to time.
Help us help you: attach a .love.
Re: Random number?
Now first off, this is not RNG, it's PRNG, a huge difference. It's not random in any way actually. The thing I suggested math.randomseed ( math.random ( ) ) is a simplified version of emulating true random number generator in software, which would not involve gathering non-random generated random bytes. The more sophisticated does involves such, like gathering user keyboard and mouse input and using it to generate new random numbers.
Re: Random number?
Yes, and? Most RNG are PRNG.Now first off, this is not RNG, it's PRNG, a huge difference.
How? You don't give any explanation or source.The thing I suggested math.randomseed ( math.random ( ) ) is a simplified version of emulating true random number generator in software
It don't change anything since the seed will is still based on time, just indirectly. It's still as possible to guess the results.
Seriously, what's the point?which would not involve gathering non-random generated random bytes. The more sophisticated does involves such, like gathering user keyboard and mouse input and using it to generate new random numbers.
We are talking about a game. A game. It's not about security. It's not about encryption. It's just about having "a number". A player won't try to guess what the (P)RNG will give.
Re: Random number?
I'm pretty shitty with number theory, but I don't think you can increase the entropy of a random stream by seeding its own randomness to itself. Depending on the generator, it may also cause it no longer to be uniform. Most implementations of C's rand function are LCGs and have a uniform distribution.
math.randomseed ( math.random ( ) ) is the same as math.randomseed(0) by the way. I guess you meant something different. Anyway, you also can't be sure that this gives you enough control so that the generator doesn't need a few steps to "warm up" again.
math.randomseed ( math.random ( ) ) is the same as math.randomseed(0) by the way. I guess you meant something different. Anyway, you also can't be sure that this gives you enough control so that the generator doesn't need a few steps to "warm up" again.
Shallow indentations.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 11 guests