C#,数值计算——Ranq2的计算方法与源程序

1 文本格式

using System;

namespace Legalsoft.Truffer

{

/// <summary>

/// Backup generator if Ranq1 has too short a period and Ran is too slow.The

/// period is 8.5E37. Calling conventions same as Ran, above.

/// </summary>

public class Ranq2

{

private ulong v { get; set; }

private ulong w { get; set; }

public Ranq2(ulong j)

{

this.v = 4101842887655102017L;

this.w = 1;

v ^= j;

w = (ulong)int64();

v = (ulong)int64();

}

public ulong int64()

{

v ^= v >> 17;

v ^= v << 31;

v ^= v >> 8;

w = 4294957665U * (w & 0xffffffff) + (w >> 32);

return (ulong)(v ^ w);

}

/// <summary>

/// Return random double-precision floating value in the range 0. to 1.

/// </summary>

/// <returns></returns>

public double doub()

{

double r= 5.42101086242752217E-20 * int64();

return (r < 0.0) ? (1 + r) : r;

}

public uint int32()

{

return (uint)int64();

}

}

}

2 代码格式

cs 复制代码
using System;

namespace Legalsoft.Truffer
{
    /// <summary>
    /// Backup generator if Ranq1 has too short a period and Ran is too slow.The
    /// period is 8.5E37. Calling conventions same as Ran, above.
    /// </summary>
    public class Ranq2
    {
        private ulong v { get; set; }
        private ulong w { get; set; }

        public Ranq2(ulong j)
        {
            this.v = 4101842887655102017L;
            this.w = 1;
            v ^= j;
            w = (ulong)int64();
            v = (ulong)int64();
        }

        public ulong int64()
        {
            v ^= v >> 17;
            v ^= v << 31;
            v ^= v >> 8;
            w = 4294957665U * (w & 0xffffffff) + (w >> 32);
            return (ulong)(v ^ w);
        }

        /// <summary>
        /// Return random double-precision floating value in the range 0. to 1.
        /// </summary>
        /// <returns></returns>
        public double doub()
        {
            double r= 5.42101086242752217E-20 * int64();
            return (r < 0.0) ? (1 + r) : r;
        }

        public uint int32()
        {
            return (uint)int64();
        }
    }
}
相关推荐
君顾110 小时前
酒吧点餐小程序系统开发实战:从架构设计到上线全流程指南
java·开发语言·酒吧
似水এ᭄往昔10 小时前
【Qt】--常用控件(显示类控件)
开发语言·qt
en.en..10 小时前
Linux fork() 工作原理
数据结构·算法
PHP实战开发录10 小时前
PHP文件上传成功为什么页面却找不到
开发语言·nginx·php·开发
地平线开发者11 小时前
bevformer算法模型详细解读
算法
liliangcsdn11 小时前
ICIR权重矩阵如何加权标准化为综合因子
算法
云小逸11 小时前
C++ 第一阶段:对象、内存与生命周期
开发语言·c++
玖玥拾12 小时前
Lua 基础语法(二)
开发语言·unity·lua
SDWAN_Cheap12 小时前
SD-WAN智能选路技术的算法与实现机制
算法·php·sdwan
王的宝库12 小时前
GO常用标准库包
开发语言·后端·golang