Random.avsi — PRNG functions for AviSynth

Functions for generating “random numbers.” The numbers are not truly random: they shouldn’t be. Instead, they need to be re-seeded for every frame, to ensure that the same frame is generated each time.

Because it’s necessary to generate the same random numbers for a given frame, and the way this PRNG works (it’s a simple linear congruential generator), setting the seed to incrementing frame values will generate somewhat lousy random numbers. They’re likely “random enough” for generic effects, but it may be worth multiplying the frame number by a large number in order to “separate” the frames a bit.

SeedRandom(seed)
Parameters:seed (int) – the seed

This should be called every frame to reset the seed. It’s important to note that due to the way this works, incrementing the seed each frame will result in really crappy random numbers (they’ll all be very similar from frame to frame). The “best” solution is to do something to make incrementing frame values seem sort of random themselves, like multiplying by a fairly large prime number or something.

NextRandomInteger()
Returns:a psuedo-random integer in the range 0-1073741823 (inclusive)
Return type:int

Returns the next random number. A call to SeedRandom() should be called at the start of every frame in order to ensure that the values generated are the same for each frame.

Random()
Returns:a psuedo-random number from 0.0 (inclusive) - 1.0 (exclusive)
Return type:float

Returns the next random number. A call to SeedRandom() should be called at the start of every frame in order to ensure that the values generated are the same for each frame.

RandomInteger(min=0, max=1073741824)

Returns the next random number. A call to SeedRandom() should be called at the start of every frame in order to ensure that the values generated are the same for each frame.

Parameters:
  • minimum (int) – minimum value to return (inclusive), defaults to 0
  • maximum (int) – maximum value to return (exclusive), defaults to 1073741824 (which is one more than the max value from NextRandomInteger())
Returns:

a psuedo-random number from min (inclusive) - max (exclusive)

Return type:

int