首页 > 其他分享 >F# bigint类型范围随机数

F# bigint类型范围随机数

时间:2022-12-29 16:46:43浏览次数:56  
标签:res bigint let 随机数 类型 data Math

F# bigint类型范围随机数 https://x.zhufn.fun/f-bigint类型范围随机数

let rnd x y =
    let r = Random()
    let mutable res = 0I
    let mutable first = true

    while not first && not (res >= x && res <= y) do
        first <- false
        let length = BigInteger.Log(y, 2) |> Math.Ceiling
        let numBytes = length / 8.0 |> Math.Ceiling |> Convert.ToInt32
        let data: byte[] = Array.zeroCreate numBytes
        r.NextBytes(data)
        res <- new BigInteger(data)

    res

标签:res,bigint,let,随机数,类型,data,Math
From: https://www.cnblogs.com/buringstraw/p/17012938.html

相关文章