indexing description: "This class wraps the mersene twister algorithme for generating pseudo random suites of numbers" author: "Manuel Oriol" date: "08/03/2007" revision: "1.0" class RANDOM_MT19937AR create make, set_seed, test feature -- random related features item: INTEGER -- the current random number, always positive forth is -- calculates the next random and stores it in item -- by default the number does not store a positive one but -- here we take the absolute value require seed_initialized: is_seed_initialized do item:=genrand_int32.abs end seed: INTEGER -- the initial seed is_seed_initialized: BOOLEAN -- stores if the suite has been initialized set_seed(a_seed: INTEGER) is -- initializes the pseudo_random suite with a seed do init_genrand(seed) is_seed_initialized:=True seed:=a_seed forth ensure seed_initialized: is_seed_initialized end make is -- initializes the seed with the current number of seconds since -- midnight, modulo 1000 local t:TIME do create t.make_now seed:=(t.seconds\\1000) init_genrand(seed) is_seed_initialized:=True forth ensure seed_initialized: is_seed_initialized end test is -- outputs a list of 100 numbers randomly chosen between 1 and 100 -- initializes the seed as well local i:INTEGER do make from i:=0 until i>100 loop print(item\\100) forth print(" ") i:=i+1 end ensure seed_initialized: is_seed_initialized end feature {NONE} -- wrapped features genrand_int32: INTEGER is -- Encapsulation of a C routine with no parameter -- returning a the next integer in the mersene twister -- pseudo random suite of number external "C (): int| %"mt19937ar.h%"" alias "genrand_int32" end init_genrand(seed_32 : INTEGER_32) is -- Encapsulation of a C routine with one parameter -- the routine sets the seed of the mersene twister external "C (unsigned long) | %"mt19937ar.h%"" alias "init_genrand" end invariant non_negative_item: item.abs=item end