F# bigint类型范围随机数

F# bigint类型范围随机数 https://zhufn.fun/archives/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
posted @   ZhuFN  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?
欢迎阅读『F# bigint类型范围随机数』
点击右上角即可分享
微信分享提示