From 0f1c2982d3b4aef5da3b2ee1f4833fc4663fc892 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Tue, 27 Aug 2019 13:51:44 +1000 Subject: [PATCH] s/gen_uint/generate_uint/g, per review comments --- extras/random/binfile.m | 24 +++++----- extras/random/marsaglia.m | 32 ++++++------- extras/random/tausworthe.m | 34 +++++++------- library/random.m | 92 +++++++++++++++++++------------------- library/random.sfc16.m | 40 ++++++++--------- library/random.sfc32.m | 58 ++++++++++++------------ library/random.sfc64.m | 56 +++++++++++------------ tests/hard_coded/random1.m | 2 +- tests/hard_coded/random2.m | 2 +- tests/hard_coded/random3.m | 2 +- 10 files changed, 171 insertions(+), 171 deletions(-) diff --git a/extras/random/binfile.m b/extras/random/binfile.m index 36be4f9ec6..14ee87c143 100644 --- a/extras/random/binfile.m +++ b/extras/random/binfile.m @@ -43,10 +43,10 @@ % % Throws an exception if the end-of-file is reached. % -:- pred gen_uint8(binfile::in, uint8::out, io::di, io::uo) is det. -:- pred gen_uint16(binfile::in, uint16::out, io::di, io::uo) is det. -:- pred gen_uint32(binfile::in, uint32::out, io::di, io::uo) is det. -:- pred gen_uint64(binfile::in, uint64::out, io::di, io::uo) is det. +:- pred generate_uint8(binfile::in, uint8::out, io::di, io::uo) is det. +:- pred generate_uint16(binfile::in, uint16::out, io::di, io::uo) is det. +:- pred generate_uint32(binfile::in, uint32::out, io::di, io::uo) is det. +:- pred generate_uint64(binfile::in, uint64::out, io::di, io::uo) is det. %---------------------------------------------------------------------------% @@ -61,10 +61,10 @@ ---> binfile(binary_input_stream). :- instance urandom(binfile, io) where [ - pred(gen_uint8/4) is binfile.gen_uint8, - pred(gen_uint16/4) is binfile.gen_uint16, - pred(gen_uint32/4) is binfile.gen_uint32, - pred(gen_uint64/4) is binfile.gen_uint64 + pred(generate_uint8/4) is binfile.generate_uint8, + pred(generate_uint16/4) is binfile.generate_uint16, + pred(generate_uint32/4) is binfile.generate_uint32, + pred(generate_uint64/4) is binfile.generate_uint64 ]. %---------------------------------------------------------------------------% @@ -84,7 +84,7 @@ %---------------------------------------------------------------------------% -gen_uint8(binfile(Stream), N, !IO) :- +generate_uint8(binfile(Stream), N, !IO) :- io.read_binary_uint8(Stream, Res, !IO), ( Res = ok(N) @@ -96,15 +96,15 @@ unexpected($pred, io.error_message(E)) ). -gen_uint16(binfile(Stream), N, !IO) :- +generate_uint16(binfile(Stream), N, !IO) :- io.read_binary_uint16_be(Stream, Res, !IO), handle_res(Res, N). -gen_uint32(binfile(Stream), N, !IO) :- +generate_uint32(binfile(Stream), N, !IO) :- io.read_binary_uint32_be(Stream, Res, !IO), handle_res(Res, N). -gen_uint64(binfile(Stream), N, !IO) :- +generate_uint64(binfile(Stream), N, !IO) :- io.read_binary_uint64_be(Stream, Res, !IO), handle_res(Res, N). diff --git a/extras/random/marsaglia.m b/extras/random/marsaglia.m index 14699f0da5..1f3e086ec9 100644 --- a/extras/random/marsaglia.m +++ b/extras/random/marsaglia.m @@ -39,10 +39,10 @@ % Generate a uniformly distributed pseudo-random unsigned integer % of 8, 16, 32 or 64 bytes, respectively. % -:- pred gen_uint8(uint8::out, random::in, random::out) is det. -:- pred gen_uint16(uint16::out, random::in, random::out) is det. -:- pred gen_uint32(uint32::out, random::in, random::out) is det. -:- pred gen_uint64(uint64::out, random::in, random::out) is det. +:- pred generate_uint8(uint8::out, random::in, random::out) is det. +:- pred generate_uint16(uint16::out, random::in, random::out) is det. +:- pred generate_uint32(uint32::out, random::in, random::out) is det. +:- pred generate_uint64(uint64::out, random::in, random::out) is det. %---------------------------------------------------------------------------% @@ -59,10 +59,10 @@ ---> random(uint64). :- instance random(random) where [ - pred(gen_uint8/3) is marsaglia.gen_uint8, - pred(gen_uint16/3) is marsaglia.gen_uint16, - pred(gen_uint32/3) is marsaglia.gen_uint32, - pred(gen_uint64/3) is marsaglia.gen_uint64 + pred(generate_uint8/3) is marsaglia.generate_uint8, + pred(generate_uint16/3) is marsaglia.generate_uint16, + pred(generate_uint32/3) is marsaglia.generate_uint32, + pred(generate_uint64/3) is marsaglia.generate_uint64 ]. init = seed(0u32, 0u32). @@ -74,26 +74,26 @@ %---------------------------------------------------------------------------% -gen_uint8(N, !R) :- - marsaglia.gen_uint32(N0, !R), +generate_uint8(N, !R) :- + marsaglia.generate_uint32(N0, !R), N1 = uint32.cast_to_int(N0 >> 24), N = uint8.cast_from_int(N1). -gen_uint16(N, !R) :- - marsaglia.gen_uint32(N0, !R), +generate_uint16(N, !R) :- + marsaglia.generate_uint32(N0, !R), N1 = uint32.cast_to_int(N0 >> 16), N = uint16.cast_from_int(N1). -gen_uint64(N, !R) :- - marsaglia.gen_uint32(A0, !R), - marsaglia.gen_uint32(B0, !R), +generate_uint64(N, !R) :- + marsaglia.generate_uint32(A0, !R), + marsaglia.generate_uint32(B0, !R), A = uint32.cast_to_uint64(A0), B = uint32.cast_to_uint64(B0), N = A + (B << 32). %---------------------------------------------------------------------------% -gen_uint32(N, R0, R) :- +generate_uint32(N, R0, R) :- R0 = random(S0), unpack_uint64(S0, SX0, SY0), A = 18000u32, diff --git a/extras/random/tausworthe.m b/extras/random/tausworthe.m index 05c88f147e..e0f4024940 100644 --- a/extras/random/tausworthe.m +++ b/extras/random/tausworthe.m @@ -67,10 +67,10 @@ % Throws an exception if the params and ustate are not the same size % (i.e., both 3-combo or both 4-combo). % -:- pred gen_uint8(params::in, uint8::out, ustate::di, ustate::uo) is det. -:- pred gen_uint16(params::in, uint16::out, ustate::di, ustate::uo) is det. -:- pred gen_uint32(params::in, uint32::out, ustate::di, ustate::uo) is det. -:- pred gen_uint64(params::in, uint64::out, ustate::di, ustate::uo) is det. +:- pred generate_uint8(params::in, uint8::out, ustate::di, ustate::uo) is det. +:- pred generate_uint16(params::in, uint16::out, ustate::di, ustate::uo) is det. +:- pred generate_uint32(params::in, uint32::out, ustate::di, ustate::uo) is det. +:- pred generate_uint64(params::in, uint64::out, ustate::di, ustate::uo) is det. % Duplicate a tausworthe RNG state. % @@ -105,10 +105,10 @@ ). :- instance urandom(params, ustate) where [ - pred(gen_uint8/4) is tausworthe.gen_uint8, - pred(gen_uint16/4) is tausworthe.gen_uint16, - pred(gen_uint32/4) is tausworthe.gen_uint32, - pred(gen_uint64/4) is tausworthe.gen_uint64 + pred(generate_uint8/4) is tausworthe.generate_uint8, + pred(generate_uint16/4) is tausworthe.generate_uint16, + pred(generate_uint32/4) is tausworthe.generate_uint32, + pred(generate_uint64/4) is tausworthe.generate_uint64 ]. :- instance urandom_dup(ustate) where [ @@ -123,26 +123,26 @@ %---------------------------------------------------------------------------% -gen_uint8(RP, N, !RS) :- - tausworthe.gen_uint32(RP, N0, !RS), +generate_uint8(RP, N, !RS) :- + tausworthe.generate_uint32(RP, N0, !RS), N1 = uint32.cast_to_int(N0 >> 24), N = uint8.cast_from_int(N1). -gen_uint16(RP, N, !RS) :- - tausworthe.gen_uint32(RP, N0, !RS), +generate_uint16(RP, N, !RS) :- + tausworthe.generate_uint32(RP, N0, !RS), N1 = uint32.cast_to_int(N0 >> 16), N = uint16.cast_from_int(N1). -gen_uint64(RP, N, !RS) :- - tausworthe.gen_uint32(RP, A0, !RS), - tausworthe.gen_uint32(RP, B0, !RS), +generate_uint64(RP, N, !RS) :- + tausworthe.generate_uint32(RP, A0, !RS), + tausworthe.generate_uint32(RP, B0, !RS), A = uint32.cast_to_uint64(A0), B = uint32.cast_to_uint64(B0), N = A + (B << 32). %---------------------------------------------------------------------------% -gen_uint32(RP, N, RS0, RS) :- +generate_uint32(RP, N, RS0, RS) :- RS0 = ustate(Seed0), Size = array.size(Seed0), rand(RP, 0, Size, 0u32, N, Seed0, Seed), @@ -182,7 +182,7 @@ seed_2(0, Size, Ks, Ps, Ds, Shft0, Shft, Mask0, Mask, Seed0, Seed), RP = params(Qs, Ps, Shft, Mask), RS0 = unsafe_promise_unique(ustate(Seed)), - tausworthe.gen_uint32(RP, _, RS0, RS). + tausworthe.generate_uint32(RP, _, RS0, RS). :- pred seed_2(int::in, int::in, array(int)::in, array(int)::in, array(uint32)::in, array(int)::array_di, array(int)::array_uo, diff --git a/library/random.m b/library/random.m index 8c1b54618e..3b9873f975 100644 --- a/library/random.m +++ b/library/random.m @@ -107,10 +107,10 @@ % Generate a uniformly distributed pseudo-random unsigned integer % of 8, 16, 32 or 64 bits, respectively. % - pred gen_uint8(uint8::out, R::in, R::out) is det, - pred gen_uint16(uint16::out, R::in, R::out) is det, - pred gen_uint32(uint32::out, R::in, R::out) is det, - pred gen_uint64(uint64::out, R::in, R::out) is det + pred generate_uint8(uint8::out, R::in, R::out) is det, + pred generate_uint16(uint16::out, R::in, R::out) is det, + pred generate_uint32(uint32::out, R::in, R::out) is det, + pred generate_uint64(uint64::out, R::in, R::out) is det ]. @@ -192,10 +192,10 @@ pred gen_uint64(uint64::out, R::in, R::out) is det % Generate a uniformly distributed pseudo-random unsigned integer % of 8, 16, 32 or 64 bits, respectively. % - pred gen_uint8(P::in, uint8::out, S::di, S::uo) is det, - pred gen_uint16(P::in, uint16::out, S::di, S::uo) is det, - pred gen_uint32(P::in, uint32::out, S::di, S::uo) is det, - pred gen_uint64(P::in, uint64::out, S::di, S::uo) is det + pred generate_uint8(P::in, uint8::out, S::di, S::uo) is det, + pred generate_uint16(P::in, uint16::out, S::di, S::uo) is det, + pred generate_uint32(P::in, uint32::out, S::di, S::uo) is det, + pred generate_uint64(P::in, uint64::out, S::di, S::uo) is det ]. @@ -460,7 +460,7 @@ pred urandom_dup(S::di, S::uo, S::uo) is det uniform_int_in_range(Start, Range0, N, !R) :- Range = uint32.det_from_int(Range0), Max = uint32.max_uint32, - gen_uint32(N0, !R), + generate_uint32(N0, !R), N1 = N0 // (Max // Range), ( if N1 < Range then N = Start + uint32.cast_to_int(N1) @@ -471,7 +471,7 @@ pred urandom_dup(S::di, S::uo, S::uo) is det uniform_uint_in_range(Start, Range0, N, !R) :- Range = uint32.cast_from_uint(Range0), Max = uint32.max_uint32, - gen_uint32(N0, !R), + generate_uint32(N0, !R), N1 = N0 // (Max // Range), ( if N1 < Range then N = Start + uint32.cast_to_uint(N1) @@ -492,7 +492,7 @@ pred urandom_dup(S::di, S::uo, S::uo) is det ). uniform_float_in_01(N, !R) :- - gen_uint64(N0, !R), + generate_uint64(N0, !R), D = 18_446_744_073_709_551_616.0, % 2^64 N = float.cast_from_uint64(N0) / D. @@ -516,7 +516,7 @@ pred urandom_dup(S::di, S::uo, S::uo) is det uniform_int_in_range(P, Start, Range0, N, !S) :- Range = uint32.det_from_int(Range0), Max = uint32.max_uint32, - gen_uint32(P, N0, !S), + generate_uint32(P, N0, !S), N1 = N0 // (Max // Range), ( if N1 < Range then N = Start + uint32.cast_to_int(N1) @@ -527,7 +527,7 @@ pred urandom_dup(S::di, S::uo, S::uo) is det uniform_uint_in_range(P, Start, Range0, N, !S) :- Range = uint32.cast_from_uint(Range0), Max = uint32.max_uint32, - gen_uint32(P, N0, !S), + generate_uint32(P, N0, !S), N1 = N0 // (Max // Range), ( if N1 < Range then N = Start + uint32.cast_to_uint(N1) @@ -548,7 +548,7 @@ pred urandom_dup(S::di, S::uo, S::uo) is det ). uniform_float_in_01(P, N, !S) :- - gen_uint64(P, N0, !S), + generate_uint64(P, N0, !S), D = 18_446_744_073_709_551_616.0, % 2^64 N = float.cast_from_uint64(N0) / D. @@ -590,24 +590,24 @@ pred urandom_dup(S::di, S::uo, S::uo) is det ---> urandom_state(R). :- instance urandom(urandom_params(R), urandom_state(R)) <= random(R) where [ - ( gen_uint8(_, N, S0, S) :- + ( generate_uint8(_, N, S0, S) :- S0 = urandom_state(R0), - gen_uint8(N, R0, R), + generate_uint8(N, R0, R), S = unsafe_promise_unique(urandom_state(R)) ), - ( gen_uint16(_, N, S0, S) :- + ( generate_uint16(_, N, S0, S) :- S0 = urandom_state(R0), - gen_uint16(N, R0, R), + generate_uint16(N, R0, R), S = unsafe_promise_unique(urandom_state(R)) ), - ( gen_uint32(_, N, S0, S) :- + ( generate_uint32(_, N, S0, S) :- S0 = urandom_state(R0), - gen_uint32(N, R0, R), + generate_uint32(N, R0, R), S = unsafe_promise_unique(urandom_state(R)) ), - ( gen_uint64(_, N, S0, S) :- + ( generate_uint64(_, N, S0, S) :- S0 = urandom_state(R0), - gen_uint64(N, R0, R), + generate_uint64(N, R0, R), S = unsafe_promise_unique(urandom_state(R)) ) ]. @@ -633,32 +633,32 @@ pred urandom_dup(S::di, S::uo, S::uo) is det :- instance random(shared_random(P, S)) <= (urandom(P, S), urandom_dup(S)) where [ - ( gen_uint8(N, R0, R) :- + ( generate_uint8(N, R0, R) :- R0 = shared_random(P, S0), S1 = unsafe_promise_unique(S0), urandom_dup(S1, _, S2), - gen_uint8(P, N, S2, S), + generate_uint8(P, N, S2, S), R = shared_random(P, S) ), - ( gen_uint16(N, R0, R) :- + ( generate_uint16(N, R0, R) :- R0 = shared_random(P, S0), S1 = unsafe_promise_unique(S0), urandom_dup(S1, _, S2), - gen_uint16(P, N, S2, S), + generate_uint16(P, N, S2, S), R = shared_random(P, S) ), - ( gen_uint32(N, R0, R) :- + ( generate_uint32(N, R0, R) :- R0 = shared_random(P, S0), S1 = unsafe_promise_unique(S0), urandom_dup(S1, _, S2), - gen_uint32(P, N, S2, S), + generate_uint32(P, N, S2, S), R = shared_random(P, S) ), - ( gen_uint64(N, R0, R) :- + ( generate_uint64(N, R0, R) :- R0 = shared_random(P, S0), S1 = unsafe_promise_unique(S0), urandom_dup(S1, _, S2), - gen_uint64(P, N, S2, S), + generate_uint64(P, N, S2, S), R = shared_random(P, S) ) ]. @@ -671,10 +671,10 @@ pred urandom_dup(S::di, S::uo, S::uo) is det ---> io_random(mutvar(R)). :- instance urandom(io_random(R), io) <= random(R) where [ - pred(gen_uint8/4) is io_random_gen_uint8, - pred(gen_uint16/4) is io_random_gen_uint16, - pred(gen_uint32/4) is io_random_gen_uint32, - pred(gen_uint64/4) is io_random_gen_uint64 + pred(generate_uint8/4) is io_random_gen_uint8, + pred(generate_uint16/4) is io_random_gen_uint16, + pred(generate_uint32/4) is io_random_gen_uint32, + pred(generate_uint64/4) is io_random_gen_uint64 ]. :- pred io_random_gen_uint8(io_random(R)::in, uint8::out, io::di, io::uo) @@ -683,7 +683,7 @@ pred urandom_dup(S::di, S::uo, S::uo) is det io_random_gen_uint8(io_random(V), N, !IO) :- impure get_mutvar(V, R0), - gen_uint8(N, R0, R), + generate_uint8(N, R0, R), impure set_mutvar(V, R). :- pred io_random_gen_uint16(io_random(R)::in, uint16::out, io::di, io::uo) @@ -692,7 +692,7 @@ impure set_mutvar(V, R). io_random_gen_uint16(io_random(V), N, !IO) :- impure get_mutvar(V, R0), - gen_uint16(N, R0, R), + generate_uint16(N, R0, R), impure set_mutvar(V, R). :- pred io_random_gen_uint32(io_random(R)::in, uint32::out, io::di, io::uo) @@ -701,7 +701,7 @@ impure set_mutvar(V, R). io_random_gen_uint32(io_random(V), N, !IO) :- impure get_mutvar(V, R0), - gen_uint32(N, R0, R), + generate_uint32(N, R0, R), impure set_mutvar(V, R). :- pred io_random_gen_uint64(io_random(R)::in, uint64::out, io::di, io::uo) @@ -710,7 +710,7 @@ impure set_mutvar(V, R). io_random_gen_uint64(io_random(V), N, !IO) :- impure get_mutvar(V, R0), - gen_uint64(N, R0, R), + generate_uint64(N, R0, R), impure set_mutvar(V, R). :- pragma promise_pure(make_io_random/4). @@ -725,10 +725,10 @@ impure new_mutvar(R, V), ---> io_urandom(P, mutvar(S)). :- instance urandom(io_urandom(P, S), io) <= urandom(P, S) where [ - pred(gen_uint8/4) is io_urandom_gen_uint8, - pred(gen_uint16/4) is io_urandom_gen_uint16, - pred(gen_uint32/4) is io_urandom_gen_uint32, - pred(gen_uint64/4) is io_urandom_gen_uint64 + pred(generate_uint8/4) is io_urandom_gen_uint8, + pred(generate_uint16/4) is io_urandom_gen_uint16, + pred(generate_uint32/4) is io_urandom_gen_uint32, + pred(generate_uint64/4) is io_urandom_gen_uint64 ]. :- pred io_urandom_gen_uint8(io_urandom(P, S)::in, uint8::out, io::di, io::uo) @@ -738,7 +738,7 @@ impure new_mutvar(R, V), io_urandom_gen_uint8(io_urandom(P, V), N, !IO) :- impure get_mutvar(V, S0), S1 = unsafe_promise_unique(S0), - gen_uint8(P, N, S1, S), + generate_uint8(P, N, S1, S), impure set_mutvar(V, S). :- pred io_urandom_gen_uint16(io_urandom(P, S)::in, uint16::out, io::di, io::uo) @@ -748,7 +748,7 @@ impure set_mutvar(V, S). io_urandom_gen_uint16(io_urandom(P, V), N, !IO) :- impure get_mutvar(V, S0), S1 = unsafe_promise_unique(S0), - gen_uint16(P, N, S1, S), + generate_uint16(P, N, S1, S), impure set_mutvar(V, S). :- pred io_urandom_gen_uint32(io_urandom(P, S)::in, uint32::out, io::di, io::uo) @@ -758,7 +758,7 @@ impure set_mutvar(V, S). io_urandom_gen_uint32(io_urandom(P, V), N, !IO) :- impure get_mutvar(V, S0), S1 = unsafe_promise_unique(S0), - gen_uint32(P, N, S1, S), + generate_uint32(P, N, S1, S), impure set_mutvar(V, S). :- pred io_urandom_gen_uint64(io_urandom(P, S)::in, uint64::out, io::di, io::uo) @@ -768,7 +768,7 @@ impure set_mutvar(V, S). io_urandom_gen_uint64(io_urandom(P, V), N, !IO) :- impure get_mutvar(V, S0), S1 = unsafe_promise_unique(S0), - gen_uint64(P, N, S1, S), + generate_uint64(P, N, S1, S), impure set_mutvar(V, S). :- pragma promise_pure(make_io_urandom/5). diff --git a/library/random.sfc16.m b/library/random.sfc16.m index 9c6068cfc8..85c39d3e9c 100644 --- a/library/random.sfc16.m +++ b/library/random.sfc16.m @@ -42,10 +42,10 @@ % Generate a uniformly distributed pseudo-random unsigned integer % of 8, 16, 32 or 64 bits, respectively. % -:- pred gen_uint8(uint8::out, random::in, random::out) is det. -:- pred gen_uint16(uint16::out, random::in, random::out) is det. -:- pred gen_uint32(uint32::out, random::in, random::out) is det. -:- pred gen_uint64(uint64::out, random::in, random::out) is det. +:- pred generate_uint8(uint8::out, random::in, random::out) is det. +:- pred generate_uint16(uint16::out, random::in, random::out) is det. +:- pred generate_uint32(uint32::out, random::in, random::out) is det. +:- pred generate_uint64(uint64::out, random::in, random::out) is det. %---------------------------------------------------------------------------% %---------------------------------------------------------------------------% @@ -65,10 +65,10 @@ ---> random(uint64). :- instance random(random) where [ - pred(gen_uint8/3) is sfc16.gen_uint8, - pred(gen_uint16/3) is sfc16.gen_uint16, - pred(gen_uint32/3) is sfc16.gen_uint32, - pred(gen_uint64/3) is sfc16.gen_uint64 + pred(generate_uint8/3) is sfc16.generate_uint8, + pred(generate_uint16/3) is sfc16.generate_uint16, + pred(generate_uint32/3) is sfc16.generate_uint32, + pred(generate_uint64/3) is sfc16.generate_uint64 ]. init = seed(0x6048_5623_5e79_371e_u64). @@ -80,7 +80,7 @@ skip(N, !R) :- ( if N > 0 then - sfc16.gen_uint16(_, !R), + sfc16.generate_uint16(_, !R), skip(N - 1, !R) else true @@ -88,28 +88,28 @@ %---------------------------------------------------------------------------% -gen_uint8(N, !R) :- - sfc16.gen_uint16(N0, !R), +generate_uint8(N, !R) :- + sfc16.generate_uint16(N0, !R), N1 = uint16.to_int(N0 >> 8), N = uint8.cast_from_int(N1). -gen_uint32(N, !R) :- - sfc16.gen_uint16(A0, !R), - sfc16.gen_uint16(B0, !R), +generate_uint32(N, !R) :- + sfc16.generate_uint16(A0, !R), + sfc16.generate_uint16(B0, !R), A = uint16.cast_to_uint(A0), B = uint16.cast_to_uint(B0), N = uint32.cast_from_uint(A + (B << 16)). -gen_uint64(N, !R) :- - sfc16.gen_uint16(A, !R), - sfc16.gen_uint16(B, !R), - sfc16.gen_uint16(C, !R), - sfc16.gen_uint16(D, !R), +generate_uint64(N, !R) :- + sfc16.generate_uint16(A, !R), + sfc16.generate_uint16(B, !R), + sfc16.generate_uint16(C, !R), + sfc16.generate_uint16(D, !R), N = pack_uint64(A, B, C, D). %---------------------------------------------------------------------------% -gen_uint16(N, random(S0), random(S)) :- +generate_uint16(N, random(S0), random(S)) :- unpack_uint64(S0, A0, B0, C0, Counter0), N = A0 + B0 + Counter0, A = B0 `xor` (B0 >> 5), diff --git a/library/random.sfc32.m b/library/random.sfc32.m index 87c2a7f4c3..903b1e7ce2 100644 --- a/library/random.sfc32.m +++ b/library/random.sfc32.m @@ -48,10 +48,10 @@ % Generate a uniformly distributed pseudo-random unsigned integer % of 8, 16, 32 or 64 bits, respectively. % -:- pred gen_uint8(params::in, uint8::out, ustate::di, ustate::uo) is det. -:- pred gen_uint16(params::in, uint16::out, ustate::di, ustate::uo) is det. -:- pred gen_uint32(params::in, uint32::out, ustate::di, ustate::uo) is det. -:- pred gen_uint64(params::in, uint64::out, ustate::di, ustate::uo) is det. +:- pred generate_uint8(params::in, uint8::out, ustate::di, ustate::uo) is det. +:- pred generate_uint16(params::in, uint16::out, ustate::di, ustate::uo) is det. +:- pred generate_uint32(params::in, uint32::out, ustate::di, ustate::uo) is det. +:- pred generate_uint64(params::in, uint64::out, ustate::di, ustate::uo) is det. % Duplicate a 32-bit SFC state. % @@ -65,10 +65,10 @@ % As above, but does not require the params argument (which is a dummy % type only needed to satisfy the typeclass interface). % -:- pred gen_uint8(uint8::out, ustate::di, ustate::uo) is det. -:- pred gen_uint16(uint16::out, ustate::di, ustate::uo) is det. -:- pred gen_uint32(uint32::out, ustate::di, ustate::uo) is det. -:- pred gen_uint64(uint64::out, ustate::di, ustate::uo) is det. +:- pred generate_uint8(uint8::out, ustate::di, ustate::uo) is det. +:- pred generate_uint16(uint16::out, ustate::di, ustate::uo) is det. +:- pred generate_uint32(uint32::out, ustate::di, ustate::uo) is det. +:- pred generate_uint64(uint64::out, ustate::di, ustate::uo) is det. %---------------------------------------------------------------------------% %---------------------------------------------------------------------------% @@ -92,10 +92,10 @@ ---> ustate(array(uint32)). :- instance urandom(params, ustate) where [ - pred(gen_uint8/4) is sfc32.gen_uint8, - pred(gen_uint16/4) is sfc32.gen_uint16, - pred(gen_uint32/4) is sfc32.gen_uint32, - pred(gen_uint64/4) is sfc32.gen_uint64 + pred(generate_uint8/4) is sfc32.generate_uint8, + pred(generate_uint16/4) is sfc32.generate_uint16, + pred(generate_uint32/4) is sfc32.generate_uint32, + pred(generate_uint64/4) is sfc32.generate_uint64 ]. :- instance urandom_dup(ustate) where [ @@ -123,7 +123,7 @@ skip(N, !S) :- ( if N > 0 then - sfc32.gen_uint32(_, !S), + sfc32.generate_uint32(_, !S), skip(N - 1, !S) else true @@ -131,40 +131,40 @@ %---------------------------------------------------------------------------% -gen_uint8(_, N, !S) :- - sfc32.gen_uint8(N, !S). +generate_uint8(_, N, !S) :- + sfc32.generate_uint8(N, !S). -gen_uint16(_, N, !S) :- - sfc32.gen_uint16(N, !S). +generate_uint16(_, N, !S) :- + sfc32.generate_uint16(N, !S). -gen_uint32(_, N, !S) :- - sfc32.gen_uint32(N, !S). +generate_uint32(_, N, !S) :- + sfc32.generate_uint32(N, !S). -gen_uint64(_, N, !S) :- - sfc32.gen_uint64(N, !S). +generate_uint64(_, N, !S) :- + sfc32.generate_uint64(N, !S). %---------------------------------------------------------------------------% -gen_uint8(N, !S) :- - sfc32.gen_uint32(N0, !S), +generate_uint8(N, !S) :- + sfc32.generate_uint32(N0, !S), N1 = uint32.cast_to_int(N0 >> 24), N = uint8.cast_from_int(N1). -gen_uint16(N, !S) :- - sfc32.gen_uint32(N0, !S), +generate_uint16(N, !S) :- + sfc32.generate_uint32(N0, !S), N1 = uint32.cast_to_int(N0 >> 16), N = uint16.cast_from_int(N1). -gen_uint64(N, !S) :- - sfc32.gen_uint32(A0, !S), - sfc32.gen_uint32(B0, !S), +generate_uint64(N, !S) :- + sfc32.generate_uint32(A0, !S), + sfc32.generate_uint32(B0, !S), A = uint32.cast_to_uint64(A0), B = uint32.cast_to_uint64(B0), N = A + (B << 32). %---------------------------------------------------------------------------% -gen_uint32(N, RS0, RS) :- +generate_uint32(N, RS0, RS) :- RS0 = ustate(S0), array.unsafe_lookup(S0, 0, A0), array.unsafe_lookup(S0, 1, B0), diff --git a/library/random.sfc64.m b/library/random.sfc64.m index 9b2d47b07f..f3a1501ed8 100644 --- a/library/random.sfc64.m +++ b/library/random.sfc64.m @@ -45,10 +45,10 @@ % Generate a uniformly distributed pseudo-random unsigned integer % of 8, 16, 32 or 64 bits, respectively. % -:- pred gen_uint8(params::in, uint8::out, ustate::di, ustate::uo) is det. -:- pred gen_uint16(params::in, uint16::out, ustate::di, ustate::uo) is det. -:- pred gen_uint32(params::in, uint32::out, ustate::di, ustate::uo) is det. -:- pred gen_uint64(params::in, uint64::out, ustate::di, ustate::uo) is det. +:- pred generate_uint8(params::in, uint8::out, ustate::di, ustate::uo) is det. +:- pred generate_uint16(params::in, uint16::out, ustate::di, ustate::uo) is det. +:- pred generate_uint32(params::in, uint32::out, ustate::di, ustate::uo) is det. +:- pred generate_uint64(params::in, uint64::out, ustate::di, ustate::uo) is det. % Duplicate a 64-bit SFC state. % @@ -62,10 +62,10 @@ % As above, but does not require the params argument (which is a dummy % type only needed to satisfy the typeclass interface). % -:- pred gen_uint8(uint8::out, ustate::di, ustate::uo) is det. -:- pred gen_uint16(uint16::out, ustate::di, ustate::uo) is det. -:- pred gen_uint32(uint32::out, ustate::di, ustate::uo) is det. -:- pred gen_uint64(uint64::out, ustate::di, ustate::uo) is det. +:- pred generate_uint8(uint8::out, ustate::di, ustate::uo) is det. +:- pred generate_uint16(uint16::out, ustate::di, ustate::uo) is det. +:- pred generate_uint32(uint32::out, ustate::di, ustate::uo) is det. +:- pred generate_uint64(uint64::out, ustate::di, ustate::uo) is det. %---------------------------------------------------------------------------% %---------------------------------------------------------------------------% @@ -89,10 +89,10 @@ ---> ustate(array(uint64)). :- instance urandom(params, ustate) where [ - pred(gen_uint8/4) is sfc64.gen_uint8, - pred(gen_uint16/4) is sfc64.gen_uint16, - pred(gen_uint32/4) is sfc64.gen_uint32, - pred(gen_uint64/4) is sfc64.gen_uint64 + pred(generate_uint8/4) is sfc64.generate_uint8, + pred(generate_uint16/4) is sfc64.generate_uint16, + pred(generate_uint32/4) is sfc64.generate_uint32, + pred(generate_uint64/4) is sfc64.generate_uint64 ]. :- instance urandom_dup(ustate) where [ @@ -124,7 +124,7 @@ skip(N, !S) :- ( if N > 0 then - sfc64.gen_uint64(_, !S), + sfc64.generate_uint64(_, !S), skip(N - 1, !S) else true @@ -132,37 +132,37 @@ %---------------------------------------------------------------------------% -gen_uint8(_, N, !S) :- - sfc64.gen_uint8(N, !S). +generate_uint8(_, N, !S) :- + sfc64.generate_uint8(N, !S). -gen_uint16(_, N, !S) :- - sfc64.gen_uint16(N, !S). +generate_uint16(_, N, !S) :- + sfc64.generate_uint16(N, !S). -gen_uint32(_, N, !S) :- - sfc64.gen_uint32(N, !S). +generate_uint32(_, N, !S) :- + sfc64.generate_uint32(N, !S). -gen_uint64(_, N, !S) :- - sfc64.gen_uint64(N, !S). +generate_uint64(_, N, !S) :- + sfc64.generate_uint64(N, !S). %---------------------------------------------------------------------------% -gen_uint8(N, !S) :- - sfc64.gen_uint64(N0, !S), +generate_uint8(N, !S) :- + sfc64.generate_uint64(N0, !S), N1 = uint64.cast_to_int(N0 >> 56), N = uint8.cast_from_int(N1). -gen_uint16(N, !S) :- - sfc64.gen_uint64(N0, !S), +generate_uint16(N, !S) :- + sfc64.generate_uint64(N0, !S), N1 = uint64.cast_to_int(N0 >> 48), N = uint16.cast_from_int(N1). -gen_uint32(N, !S) :- - sfc64.gen_uint64(N0, !S), +generate_uint32(N, !S) :- + sfc64.generate_uint64(N0, !S), N = uint32.cast_from_uint64(N0 >> 32). %---------------------------------------------------------------------------% -gen_uint64(N, RS0, RS) :- +generate_uint64(N, RS0, RS) :- RS0 = ustate(S0), array.unsafe_lookup(S0, 0, A0), array.unsafe_lookup(S0, 1, B0), diff --git a/tests/hard_coded/random1.m b/tests/hard_coded/random1.m index b0f78278eb..6e77644ae0 100644 --- a/tests/hard_coded/random1.m +++ b/tests/hard_coded/random1.m @@ -37,7 +37,7 @@ test(Count, RP, !RS, !IO) :- ( if Count > 0 then - random.gen_uint64(RP, N, !RS), + random.generate_uint64(RP, N, !RS), A = cast_to_int(N >> 32), B = cast_to_int(N /\ 0xffffffffu64), io.format("%08x%08x\n", [i(A), i(B)], !IO), diff --git a/tests/hard_coded/random2.m b/tests/hard_coded/random2.m index 5f53391b36..06709f0b16 100644 --- a/tests/hard_coded/random2.m +++ b/tests/hard_coded/random2.m @@ -38,7 +38,7 @@ test(Count, !R, !IO) :- ( if Count > 0 then - random.gen_uint64(N, !R), + random.generate_uint64(N, !R), A = cast_to_int(N >> 32), B = cast_to_int(N /\ 0xffffffffu64), io.format("%08x%08x\n", [i(A), i(B)], !IO), diff --git a/tests/hard_coded/random3.m b/tests/hard_coded/random3.m index fcadb6c08f..ad0b411f8b 100644 --- a/tests/hard_coded/random3.m +++ b/tests/hard_coded/random3.m @@ -38,7 +38,7 @@ test(Count, M, !IO) :- ( if Count > 0 then - random.gen_uint64(M, N, !IO), + random.generate_uint64(M, N, !IO), A = cast_to_int(N >> 32), B = cast_to_int(N /\ 0xffffffffu64), io.format("%08x%08x\n", [i(A), i(B)], !IO),