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();
        }
    }
}
相关推荐
No0d1es1 分钟前
2024年12月青少年软件编程(C语言/C++)等级考试试卷(三级)
c语言·开发语言·青少年编程·电子学会·三级
犬余6 分钟前
《Java源力物语》-4.集合府邸的新秀
java·开发语言
yuanbenshidiaos6 分钟前
QT-------认识QT
开发语言·qt
海螺姑娘的小魏13 分钟前
Effective C++ 条款 16:成对使用 `new` 和 `delete` 时要采取相同形式
开发语言·c++
neter.asia31 分钟前
C# 窗体应用程序嵌套web网页,基于谷歌浏览器内核(含源码)
开发语言·c#
cxylay42 分钟前
自适应滤波算法分类及详细介绍
算法·分类·自适应滤波算法·自适应滤波·主动噪声控制·anc
2301_809177471 小时前
sqoop,flume草稿
开发语言
茶猫_1 小时前
力扣面试题 - 40 迷路的机器人 C语言解法
c语言·数据结构·算法·leetcode·机器人·深度优先
轻浮j1 小时前
Sentinel底层原理以及使用算法
java·算法·sentinel
潜意识起点1 小时前
Java数组:静态初始化与动态初始化详解
java·开发语言·python