Re: [racket-users] Generate really large random numbers in Racket

2019-04-03 Thread Shaobo He
Thank you. I think `random-natural` works for my case.

'Paulo Matos' via Racket Users  于2019年4月2日周二
上午12:49写道:

> Check the math library by Neil Toronto:
>
> https://docs.racket-lang.org/math/base.html?q=random#%28part._.Random_.Number_.Generation%29
>
> (random-natural k) → Natural
>
>   k : Integer
>
> Returns a random natural number less than k, which must be positive. Use
> (random-natural k) instead of (random k) when k could be larger than
> 4294967087.
>
>
> On 01/04/2019 23:31, polarish...@gmail.com 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-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> Paulo Matos
>
> --
> 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.
>

-- 
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.


Re: [racket-users] Generate really large random numbers in Racket

2019-04-03 Thread Evelyn Mitchell
If you are implementing random number generators, you may want to use a
test suite:
Tu01 http://simul.iro.umontreal.ca/testu01/tu01.html
or
Dieharder https://webhome.phy.duke.edu/~rgb/General/rand_rate/rand_rate.abs

Hope this helps,
Evelyn Mitchell
efmph...@gmail.com

On Tue, Apr 2, 2019 at 12:55 AM 'Paulo Matos' via Racket Users <
racket-users@googlegroups.com> wrote:

>
>
> On 01/04/2019 23:37, Robby Findler wrote:
> > 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
> >
>
> Awesome! I just skimmed the paper and the enumeration part brought
> memories of a technique we developed for unbounded model checking almost
> a decade ago.
>
> Your figure 3 is not too far from our figures 4 and 5 on page 9 of:
>
> https://www.researchgate.net/publication/225399880_A_Lazy_Unbounded_Model_Checker_for_Event-B
>
> Also, I should point out that all this Lazy Unbounded Model Checking
> research was developed in the good old PLT Scheme. :)
>
> Should check if the thing still runs in todays Racket...
>
> Now I should really grab a coffee and read your paper properly!
>
> Paulo Matos
>
> > Robby
> >
> > On Mon, Apr 1, 2019 at 4:31 PM  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-users+unsubscr...@googlegroups.com.
> >> For more options, visit https://groups.google.com/d/optout.
> >
>
> --
> Paulo Matos
>
> --
> 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.
>

-- 
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.


Re: [racket-users] Generate really large random numbers in Racket

2019-04-01 Thread 'Paulo Matos' via Racket Users



On 01/04/2019 23:37, Robby Findler wrote:
> 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
> 

Awesome! I just skimmed the paper and the enumeration part brought
memories of a technique we developed for unbounded model checking almost
a decade ago.

Your figure 3 is not too far from our figures 4 and 5 on page 9 of:
https://www.researchgate.net/publication/225399880_A_Lazy_Unbounded_Model_Checker_for_Event-B

Also, I should point out that all this Lazy Unbounded Model Checking
research was developed in the good old PLT Scheme. :)

Should check if the thing still runs in todays Racket...

Now I should really grab a coffee and read your paper properly!

Paulo Matos

> Robby
> 
> On Mon, Apr 1, 2019 at 4:31 PM  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-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 

-- 
Paulo Matos

-- 
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.


Re: [racket-users] Generate really large random numbers in Racket

2019-04-01 Thread 'Paulo Matos' via Racket Users
Check the math library by Neil Toronto:
https://docs.racket-lang.org/math/base.html?q=random#%28part._.Random_.Number_.Generation%29

(random-natural k) → Natural

  k : Integer

Returns a random natural number less than k, which must be positive. Use
(random-natural k) instead of (random k) when k could be larger than
4294967087.


On 01/04/2019 23:31, polarish...@gmail.com 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-users+unsubscr...@googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.

-- 
Paulo Matos

-- 
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.


Re: [racket-users] Generate really large random numbers in Racket

2019-04-01 Thread WarGrey Gyoudmon Ju
Hi, I am writing SSH in pure typed racket,
Generating a big random primes is one of the tasks and I just finished it.

https://github.com/wargrey/lambda-shell/blob/master/ssh/digitama/algorithm/random.rkt
https://github.com/wargrey/lambda-shell/blob/master/ssh/digitama/algorithm/rsa.rkt

Before I write my own routines, I have read the source code of racket/math,
OpenSSH and OpenSSL.
So I think the only security problem is I am not using `crypto-random-bytes

`.

By the way, racket/math may already have been fit you.


On Tue, Apr 2, 2019 at 6:06 AM Alex Harsanyi  wrote:

> 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 
> 
>  (random-bignum bits)
>   (define 
> 
>  num-bytes (exact-ceiling 
> 
>  (/ 
> 
>  bits 8)))
>   (for/fold 
> 
>  ([result 0])
> ([byte (in-bytes 
> 
>  (crypto-random-bytes 
> 
>  num-bytes))])
> (+ 
> 
>  byte (* 
> 
>  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  于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  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.
>>> > 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.
>

-- 
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.


Re: [racket-users] Generate really large random numbers in Racket

2019-04-01 Thread Alex Harsanyi
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 

 (random-bignum bits)
  (define 

 num-bytes (exact-ceiling 

 (/ 

 bits 8)))
  (for/fold 

 ([result 0])
([byte (in-bytes 

 (crypto-random-bytes 

 num-bytes))])
(+ 

 byte (* 

 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 > 于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 > 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 .
>> > 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.


Re: [racket-users] Generate really large random numbers in Racket

2019-04-01 Thread Shaobo He
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  于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  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-users+unsubscr...@googlegroups.com.
> > 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.


Re: [racket-users] Generate really large random numbers in Racket

2019-04-01 Thread Robby Findler
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  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-users+unsubscr...@googlegroups.com.
> 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.


[racket-users] Generate really large random numbers in Racket

2019-04-01 Thread polarishehn
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-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.