Blog RSS Feed Subscribe

Jordi Boggiano

Jordi Boggiano Passionate web developer, specialized in web performance and php. Partner at Nelmio, information junkie and speaker.

Categories

SeededRand

Mersenne Twister implementation for AS3.

This is an AS3 port of the C Mersenne Twister by Takuji Nishimura and Makoto Matsumoto.

It is used to generate unique numbers based on the provided seed.

More infos in my post about it

// Create a new generator and provide it with a unique seed. 
// The seed will define what numbers are produced so don't 
// forget to change it if you want another sequence 
var gen:SeededRand = new SeededRand(4390); 
  
// You can get three types of numbers : 
  
// An integer (32bits) - 2032224733 
trace(gen.int32); 
  
// A float (between 0 and 1) - 0.06299788135243481 
trace(gen.float); 
  
// An integer within a range - 4 
gen.setRange(1, 10); 
trace(gen.ranged);

DownloadDownload

Last updated on : 13/03/2008, Posted in ActionScript 3