C#,数值计算——Ranlim32的计算方法与源程序
最佳答案 问答题库588位专家为你答疑解惑
1 文本格式
using System;
namespace Legalsoft.Truffer
{
/// <summary>
/// High-quality random generator using only 32-bit arithmetic.Same conventions
/// as Ran.Period is 3.11E37 . Recommended only when 64-bit arithmetic is not
/// available.
/// </summary>
public class Ranlim32
{
private uint u { get; set; }
private uint v { get; set; } = 0x85ca18e3; // 0x85ca18e3=2244614371;
private uint w1 { get; set; } = 521288629;
private uint w2 { get; set; } = 362436069;
public Ranlim32(uint j)
{
this.v = 2244614371U;
this.w1 = 521288629U;
this.w2 = 362436069U;
u = j ^ v; int32();
v = u; int32();
}
public uint int32()
{
u = u * 2891336453U + 1640531513U;
v ^= v >> 13;
v ^= v << 17;
v ^= v >> 5;
w1 = (uint)(33378 * (w1 & 0xffff) + (w1 >> 16));
w2 = (uint)(57225 * (w2 & 0xffff) + (w2 >> 16));
uint x = u ^ (u << 9);
x ^= x >> 17;
x ^= x << 6;
uint y = w1 ^ (w1 << 17);
y ^= y >> 15;
y ^= y << 5;
return (x + v) ^ (y + w2);
}
public double doub()
{
double r = 2.32830643653869629E-10 * int32();
return (r < 0.0) ? (1 + r) : r;
}
public double truedoub()
{
return 2.32830643653869629E-10 * (int32() + 2.32830643653869629E-10 * int32());
}
}
}
2 代码格式
using System;namespace Legalsoft.Truffer
{/// <summary>/// High-quality random generator using only 32-bit arithmetic.Same conventions/// as Ran.Period is 3.11E37 . Recommended only when 64-bit arithmetic is not/// available./// </summary>public class Ranlim32{private uint u { get; set; }private uint v { get; set; } = 0x85ca18e3; // 0x85ca18e3=2244614371;private uint w1 { get; set; } = 521288629;private uint w2 { get; set; } = 362436069;public Ranlim32(uint j){this.v = 2244614371U;this.w1 = 521288629U;this.w2 = 362436069U;u = j ^ v; int32();v = u; int32();}public uint int32(){u = u * 2891336453U + 1640531513U;v ^= v >> 13;v ^= v << 17;v ^= v >> 5;w1 = (uint)(33378 * (w1 & 0xffff) + (w1 >> 16));w2 = (uint)(57225 * (w2 & 0xffff) + (w2 >> 16));uint x = u ^ (u << 9);x ^= x >> 17;x ^= x << 6;uint y = w1 ^ (w1 << 17);y ^= y >> 15;y ^= y << 5;return (x + v) ^ (y + w2);}public double doub(){double r = 2.32830643653869629E-10 * int32();return (r < 0.0) ? (1 + r) : r;}public double truedoub(){return 2.32830643653869629E-10 * (int32() + 2.32830643653869629E-10 * int32());}}
}
99%的人还看了
相似问题
- 使用opencv将sRGB格式的图片转换为BT.2020格式【sRGB】【BT.2020】
- YOLO目标检测——卫星遥感多类别检测数据集下载分享【含对应voc、coco和yolo三种格式标签】
- VMware 系列:戴尔服务器配置(格式数据、RAID5、安装ESXI)以及相关问题
- qcow2、raw、vmdk等镜像格式工具
- 微信小程序发货信息录入接口 错误上传时间非法,请按照 RFC 3339 格式填写?
- 2015-2020年全国地区生产总值及一二三产构成数据总览,shp/excel格式
- 媒体格式转换软件Permute 3 mac中文版软件特点
- 智能门禁刷脸照片格式gif、bmp,png转换,转换base64
- MAC地址_MAC地址格式_以太网的MAC帧_基础知识
- 硬盘无法格式化怎么办?
猜你感兴趣
版权申明
本文"C#,数值计算——Ranlim32的计算方法与源程序":http://eshow365.cn/6-15789-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!