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();
        }
    }
}
相关推荐
民乐团扒谱机5 分钟前
【AI笔记】精密光时频传递技术核心内容总结
人工智能·算法·光学频率梳
sycmancia22 分钟前
C++进阶01——示例
开发语言·c++
CoderCodingNo25 分钟前
【GESP】C++五级/四级练习题 luogu-P1413 坚果保龄球
开发语言·c++·算法
眼眸流转28 分钟前
Java代码变更影响分析(一)
java·开发语言
Yvonne爱编码32 分钟前
JAVA数据结构 DAY4-ArrayList
java·开发语言·数据结构
Next_Tech_AI1 小时前
别用 JS 惯坏了鸿蒙
开发语言·前端·javascript·个人开发·ai编程·harmonyos
chillxiaohan1 小时前
GO学习记录——多文件调用
开发语言·学习·golang
2301_822366351 小时前
C++中的命令模式变体
开发语言·c++·算法
一刻钟.1 小时前
C#高级语法之线程与任务
开发语言·c#
追逐梦想的张小年1 小时前
JUC编程03
java·开发语言·idea