indexing description: "Provides a random number generator instance" license: "MIT license (see ../license.txt)" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" class P2P_RANDOM_SHARED inherit DT_SHARED_SYSTEM_CLOCK export {NONE} all end feature {NONE} -- Implementation rand: RANDOM is -- Create unique random number generator and seed with number of seconds since epoch indexing once_status: global local seed: NATURAL_64 seed_32: INTEGER cur_time: DT_DATE_TIME once cur_time := utc_system_clock.date_time_now -- Compute the seed as the number of milliseconds sind the beginning of unix timestamp. seed := cur_time.day_count.to_natural_64 * cur_time.seconds_in_day.to_natural_64 + cur_time.second_count.to_natural_64 seed := seed * 1000 + cur_time.millisecond.to_natural_64 -- this trick from RFC 4122 helps to preserve more meaning of 64bit integer to a 32bit integer seed_32 := ((seed |>> 32).bit_xor (seed).as_integer_32 & 0x7FFFFFFF) create Result.set_seed (seed_32) Result.start end end