random numbers

This question should apply to many game programs :
When there is a random number, how does one seed that number after it is generated? i used the GameLogic.getRandomFloat() because the actuator is predictable, but now when 2 numbers are generated at once they are the same, I want an ID number, 0-7, to offset the random number.
Any Ideas? Can I just “seed” the getrandomfloat() function somehow?


if you only need (or could adapt to use only) integers you can write your own random number routine

pretty simple really, but I will have to look for some code for you to be more accurate

essentially you just have one big number, you add something random to it, and store the result over the first number.

the result mod the number of values you want to get is your random number

but now that I think about it it doesn’t make enough sense to be implemented, guess I will have to find that code.

Well here’s one way which is slightly better -
x=randomnumber(min,max) [a user function]
if x>max:

Hope someone finds that informative, I’m off to read some python docs, maybe there is a available function.

Thanks for the reply xz3ero but you don’t need to go out of your way to track down info for it. (Hope you find the time to work on your own programs/games with all the questions you answer)

what does

[a user function]

should i include that?

or should i put

Dir = randomnumber(1,4)

> and does the random number include the min and max or would it 
> return 2 & 3

Heh old post.

don’t use “randomnumber()”, you’ll have to work out usingGameLogic.getRandomFloat()
which gives you a number between 0 and 1 I think.

how do i get one between and including 1 and 4

Between 1 and 4?

1.0 + (random_number * 3.0)

Truncate to an integer if necessary.

I haven’t fooled with randoms in GameBlender but I suppose that I just assume that GameBlender would take care of seeding the random-number generator at the start of each game, so that you do not need to re-seed it yourself unless for some reason you need a repeatable sequence of values. (And then, storing the values in an array is usually simpler.)