caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] zarith: how to pick a random integer?
@ 2019-11-27 21:31 François Pottier
  2019-11-27 21:51 ` Carl Eastlund
  0 siblings, 1 reply; 5+ messages in thread
From: François Pottier @ 2019-11-27 21:31 UTC (permalink / raw)
  To: caml users


Hello,

I am using zarith and would like to pick a random integer
comprised between 0 and some bound. I would like a function
Z.random of type Z.t -> Z.t, but this function seems to be
missing, and I am not sure how to program it in an efficient
and correct way. Any suggestions would be welcome. Thanks!

-- 
François Pottier
francois.pottier@inria.fr
http://gallium.inria.fr/~fpottier/

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [Caml-list] zarith: how to  pick a random integer?
@ 2019-11-28  9:27 basile
  2019-11-28  9:30 ` basile
  0 siblings, 1 reply; 5+ messages in thread
From: basile @ 2019-11-28  9:27 UTC (permalink / raw)
  To: François Pottier; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1060 bytes --]


On Wednesday, November 27, 2019 22:31 CET, François Pottier <francois.pottier@inria.fr> wrote:
 
Hello,

I am using zarith and would like to pick a random integer
comprised between 0 and some bound. I would like a function
Z.random of type Z.t -> Z.t, but this function seems to be
missing, and I am not sure how to program it in an efficient
and correct way. Any suggestions would be welcome. Thanks!

 
I tend to believe that the following idea might be good, but please check with real probability experts. I definitely am not one (but one of my best colleagues is one).

Let B be the bound.

You take a random number modulus 2*B. Let R be that number

You modelize the [0;B[ interval as a ring of numbers. For example if B is 5 : 0 -> 1 -> 2 -> 3 -> 4 -> 0 -> 1 -> .... ad infinitium


You memoize the previously given random number N

On that ring, you go R steps forward and obtain P. That is your new random number and on the next iteration the R would be that P

But check with an expert, I am not one

--

Basile
 

[-- Attachment #2: Type: text/html, Size: 1325 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-11-28  9:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-27 21:31 [Caml-list] zarith: how to pick a random integer? François Pottier
2019-11-27 21:51 ` Carl Eastlund
2019-11-28  8:13   ` François Pottier
2019-11-28  9:27 basile
2019-11-28  9:30 ` basile

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).