[m-users.] Random Number Generator
Volker Wysk <[email protected]>
| Newsgroups | gmane.comp.lang.mercury.general |
|---|---|
| Message-ID | <[email protected]> |
Hi
I find the documentation of the random* modules a litte confusing. I got
this far (this works):
main(!IO) :-
open_system_rng(MaybeHandle, !IO),
(
MaybeHandle = maybe.ok(Handle),
random.system_rng.generate_uint64(Handle, First, !IO),
random.system_rng.generate_uint64(Handle, Second, !IO),
random.system_rng.generate_uint64(Handle, Third, !IO),
random.sfc64.seed(First, Second, Third, P, State),
make_io_urandom(P, State, M, !IO),
generate_uint64(M, R, !IO),
io.format("R=%s\n", [s(string.string(R))], !IO)
;
MaybeHandle = maybe.error(Msg),
io.format("Error opening system random number generator:\n%s\n",
[s(Msg)], !IO)
).
I don't like the argument M of make_io_random/5 and generate_uint64/4, which
needs to be passed around when using the random number generator. The RNG is
attached to the IO state only half-way, the M arument still needs to be
passed around. I'd like to have some predicate "generate_uint64(uint64::out,
io::di, io::uo)", which doesn't need the M argument, because all is stored
in the IO state.
Actually, that M argument is of type params and this is a dummy type (from
the source code of random.sfc64):
:- type params
---> params.
It's the same for random.sfc32, but not for random.sfc16. And the module
random.sfc64 defines this:
:- pred generate_uint64(uint64::out, ustate::di, ustate::uo) is det.
That's looks like what I need, but there isn't such a member of the urandom
type class, which I need to use when I want it to be attached to the IO
state.
I hope I've made sense.
Cheers,
Volker
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE6QXGh82Ov3+2nrxp+K4ydFOsHoUFAmTGRssACgkQ+K4ydFOs HoUvhg//Ukj3ZpO1dEUxz1zt8fCCLkJ8vNJRmf/7fhXIKc/Hlya7KO5QKoC9KKaA DYxbYfpdPOGC9zW7x6v/t/8wvgDbud74qV9wR8C5rY99OiS8EFaVg7tf1jRFTlJ7 69GWvUp5cJHNybetlY6YrN5y26qWQX7UcAHFBT2Xw5epgBV5OohJwjepJCnSINQs uwqmuPQrtW2E44fQW0h4vAEHpnoH29ZDHwJZWlCa4oH1ivYTiG4BZa8V7XWhWidy h1BUSwEybVZBa7POT3m3ljhAva+/+PEFnHRzKfdaNphvIaZW20yZ8x5noXKvQg8j XEzkvkF9/d/NRTGoGLvq+A5IC5RCBIrnEj5is7O7AZFPGCn8QXaR3XiH8a5galFf o4lGT9gRCKRTwsBODAMhP3hBe2sSh6E4YLbm/IwqTWbqKKHcXcxNed1+scCYmHEF E9YAQ0iqbhubKZcRvA7xFwuDaOBnu1GlSgxUW6Oo+1icUf9bK1ZhTasQM88WMGXW SDH2ZLtkpV0kvWLXZTeYCStCZHh4N4GpYb2v0dUSkssEM3IHE1Lk9ANTZcmpVFMO Qwb8QzdBXxeE3Hdk5ZXMDINqhH65ZrYCvbrNpWUpcTwaCJS/6fR4epwKLEoOXQqA 43FC5kMOcjutg/e0rBXUOR5ykHITW+HOPIFhgHYKlGTNonq9sgQ= =Qyux -----END PGP SIGNATURE-----