在類庫橫行的今天
view plaincopy to clipboardprint?
using System;
namespace MyRandom
{
public class Rand
{
private long seed; //隨機數種子
//用系統時間作為隨機種子
public Rand()
{
string str = DateTime
str += DateTime
str += DateTime
str += DateTime
str += DateTime
this
}
//用戶自定義隨機種子
public Rand(long Value)
{
this
}
//產生非負偽隨機數
public long Next()
{
long l = this
l = l * l;
string strTime = l
int w = strTime
string str =
for (int i = w; i < strTime
str += strTime[i];
l = long
return l;
}
//產生上限為Value的偽隨機數
public long Next(long Value)
{
if (Value <
return
long l = this
l = l * l;
string strTime = l
int w = strTime
string str =
for (int i = w; i < strTime
str += strTime[i];
l = long
return l % Value;
}
//產生下限為minValue上限為maxValue的偽隨機數
public long Next(long minValue
{
if (minValue <
return
long l = this
l = l * l;
string strTime = l
int w = strTime
string str =
for (int i = w; i < strTime
str += strTime[i];
l = long
return l % (maxValue
}
//偽隨機數填充指定的比特數組
public void NextBytes(byte[] buffer)
{
long Value =
Value = this
for (int i =
{
Value = Value * Value;
string strTime = Value
int w = strTime
string str =
for (int j = w; j < strTime
str += strTime[j];
Value = long
Value = Value %
buffer[i] = (byte)Value;
}
}
//產生
public double NextDouble()
{
long l = this
if (l ==
return
l = l * l;
string strTime = l
int w = strTime
string str =
for (int i = w; i < strTime
str += strTime[i];
double d = double
return d;
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/13253.html