signature SPECCHECK_RANDOM = sig type rand (*creates a new random seed*) val new : unit -> rand (*creates a new random seed from a given one*) val next : rand -> rand (*use this function for reproducible randomness; inputs \<le> 0 are mapped to 1*) val deterministic_seed : int -> rand
(*returns a real in the unit interval [0;1]; theoretically, with 2^31-2 equidistant discrete
values*) val real_unit : rand -> real * rand
(*splits a seed into two new independent seeds*) val split : rand -> rand * rand end
(*TODO: Time is not sufficiently random when polled rapidly!*) fun new () =
Time.now ()
|> Time.toMicroseconds
|> (fn x => Int.max (1, x mod m)) (*The seed must be within [1;m)*)
|> next
fun deterministic_seed r = Int.max (1, r mod m)
fun real_unit r = ((Real.fromInt (r - 1)) / (Real.fromInt (m - 2)), next r)
(*TODO: In theory, the current implementation could return two seeds directly adjacent in the
sequence of the pseudorandom number generator. Practically, however, it should be good enough.*) fun split r = let val r0 = next r val r1 = r - r0 in (next r0, next r1) end
end
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-10)
¤