You can use `crypto-random-bytes` to generate large random numbers, 
however, that function returns a string of bytes, which you have to combine 
into an integer:

(define 
<http://docs.racket-lang.org/reference/define.html#(form._((lib._racket/private/base..rkt)._define))>
 (random-bignum bits)
  (define 
<http://docs.racket-lang.org/reference/define.html#(form._((lib._racket/private/base..rkt)._define))>
 num-bytes (exact-ceiling 
<http://docs.racket-lang.org/reference/generic-numbers.html#(def._((lib._racket/math..rkt)._exact-ceiling))>
 (/ 
<http://docs.racket-lang.org/reference/generic-numbers.html#(def._((quote._~23~25kernel)._/))>
 bits 8)))
  (for/fold 
<http://docs.racket-lang.org/reference/for.html#(form._((lib._racket/private/base..rkt)._for/fold))>
 ([result 0])
            ([byte (in-bytes 
<http://docs.racket-lang.org/reference/sequences.html#(def._((lib._racket/private/base..rkt)._in-bytes))>
 (crypto-random-bytes 
<http://docs.racket-lang.org/reference/generic-numbers.html#(def._((lib._racket/random..rkt)._crypto-random-bytes))>
 num-bytes))])
    (+ 
<http://docs.racket-lang.org/reference/generic-numbers.html#(def._((quote._~23~25kernel)._+))>
 byte (* 
<http://docs.racket-lang.org/reference/generic-numbers.html#(def._((quote._~23~25kernel)._*))>
 result 256))))


Alex.

On Tuesday, April 2, 2019 at 5:39:46 AM UTC+8, Shaobo He wrote:
>
> Thank you for your reply. This is my thought too but I'm not sure if 
> combining multiple random bits break any good properties of random number 
> generators. Sorry I should've mentioned it. I was talking about bounded 
> random numbers.
>
> Robby Findler <ro...@cs.northwestern.edu <javascript:>> 于2019年4月1日周一 
> 下午3:35写道:
>
>> Generate multiples of those and combine them (shifting old ones over
>> and adding new ones as the lowest digits)?
>>
>> I'm not sure of a good way to generate nats uniformly at random where
>> you don't specify an upper bound, but Neil Toronto suggested something
>> crazy we used this paper:
>> http://users.cs.northwestern.edu/~robby/pubs/papers/jfp2017-nfmf.pdf
>>
>> Robby
>>
>> On Mon, Apr 1, 2019 at 4:31 PM <polar...@gmail.com <javascript:>> wrote:
>> >
>> > Hello everyone,
>> >
>> > It appears that the largest number returned by the random function in 
>> Racket is 4294967087-1 for a good reason. Are there any libraries or simple 
>> approaches to generate a number larger than that?
>> >
>> > Thanks,
>> > Shaobo
>> >
>> > --
>> > You received this message because you are subscribed to the Google 
>> Groups "Racket Users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an email to racket...@googlegroups.com <javascript:>.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to