Random rational numbers generation

前端 未结 3 1349
失恋的感觉
失恋的感觉 2021-02-04 04:26

Rationals are enumerable. For example this code finds k-th rational in open interval 0..1, with ordering that {n1, d1} is before {n2, d2} if (d1&

3条回答
  •  长发绾君心
    2021-02-04 05:01

    With a bound on the denominator, the rationals aren't uniformly distributed (1/2 gets separated from everything else by a nice gap, for example.

    That said, would something like

    In[300]:= Rationalize[RandomReal[1, 10], 0.001]
    
    Out[300]= {17/59, 45/68, 11/31, 9/16, 1/17, 13/22, 7/10, 1/17, 5/21, 8/39}
    

    work for you?

提交回复
热议问题