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();
        }
    }
}
相关推荐
坚持编程的菜鸟2 分钟前
LeetCode每日一题——螺旋矩阵
c语言·算法·leetcode·矩阵
汉克老师5 分钟前
GESP2025年9月认证C++四级( 第三部分编程题(1)排兵布阵)
c++·算法·gesp4级·gesp四级
(●—●)橘子……9 分钟前
记力扣2009:使数组连续的最少操作数 练习理解
数据结构·python·算法·leetcode
GalaxyPokemon12 分钟前
LeetCode - 1171.
算法·leetcode·链表
@Kerry~30 分钟前
phpstudy .htaccess 文件内容
java·开发语言·前端
CRMEB系统商城30 分钟前
CRMEB多商户系统(PHP)v3.3正式发布,同城配送上线[特殊字符]
java·开发语言·小程序·php
budingxiaomoli38 分钟前
算法---双指针一
算法
iナナ40 分钟前
Java优选算法——位运算
java·数据结构·算法·leetcode
热爱生活的猴子43 分钟前
算法279. 完全平方数
算法·深度优先
sali-tec1 小时前
C# 基于halcon的视觉工作流-章45-网格面划痕
开发语言·算法·计算机视觉·c#