本文整理汇总了C#中MersenneTwister类的典型用法代码示例。如果您正苦于以下问题:C# MersenneTwister类的具体用法?C# MersenneTwister怎么用?C# MersenneTwister使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MersenneTwister类属于命名空间,在下文中一共展示了MersenneTwister类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnEnter
// Code that runs on entering the state.
public override void OnEnter()
{
MersenneTwister random = new MersenneTwister();
storeResult.Value = random.Next(max.Value);
Finish();
}
示例2: Create
public static MersenneTwister Create()
{
var random = new Random();
var seed = (uint) (random.Next(int.MaxValue) + (uint) random.Next(int.MaxValue));
var twiseter = new MersenneTwister(seed);
return twiseter;
}
示例3: GbmState
public GbmState(IRegressionProblemData problemData, ILossFunction lossFunction, uint randSeed, int maxSize, double r, double m, double nu) {
// default settings for MaxSize, Nu and R
this.maxSize = maxSize;
this.nu = nu;
this.r = r;
this.m = m;
this.randSeed = randSeed;
random = new MersenneTwister(randSeed);
this.problemData = problemData;
this.trainingRows = problemData.TrainingIndices.ToArray();
this.testRows = problemData.TestIndices.ToArray();
this.lossFunction = lossFunction;
int nRows = trainingRows.Length;
y = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, trainingRows).ToArray();
treeBuilder = new RegressionTreeBuilder(problemData, random);
activeIdx = Enumerable.Range(0, nRows).ToArray();
var zeros = Enumerable.Repeat(0.0, nRows).ToArray();
double f0 = lossFunction.LineSearch(y, zeros, activeIdx, 0, nRows - 1); // initial constant value (mean for squared errors)
pred = Enumerable.Repeat(f0, nRows).ToArray();
predTest = Enumerable.Repeat(f0, testRows.Length).ToArray();
pseudoRes = new double[nRows];
models = new List<IRegressionModel>();
weights = new List<double>();
// add constant model
models.Add(new ConstantModel(f0, problemData.TargetVariable));
weights.Add(1.0);
}
示例4: ArgumentCreaterDistributionsTest
public void ArgumentCreaterDistributionsTest() {
var trees = new List<ISymbolicExpressionTree>();
var grammar = Grammars.CreateArithmeticAndAdfGrammar();
var random = new MersenneTwister(31415);
int failedOps = 0;
for (int i = 0; i < POPULATION_SIZE; i++) {
ISymbolicExpressionTree tree;
do {
tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_LENGTH, MAX_TREE_DEPTH);
SubroutineCreater.CreateSubroutine(random, tree, MAX_TREE_LENGTH, MAX_TREE_DEPTH, 3, 3);
} while (!TreeHasAdfWithParameter(tree, 3));
var success = ArgumentCreater.CreateNewArgument(random, tree, 60000, 100, 3, 3);
if (!success) failedOps++;
Util.IsValid(tree);
trees.Add(tree);
}
// difficult to make sure that create argument operations succeed because trees are macro-expanded can potentially become very big
// => just test if only a small proportion fails
Assert.IsTrue(failedOps < POPULATION_SIZE * 0.05); // only 5% may fail
Console.WriteLine("ArgumentCreator: " + Environment.NewLine +
"Failed operations: " + failedOps * 100.0 / POPULATION_SIZE + " %" + Environment.NewLine +
Util.GetSizeDistributionString(trees, 200, 20) + Environment.NewLine +
Util.GetFunctionDistributionString(trees) + Environment.NewLine +
Util.GetNumberOfSubtreesDistributionString(trees) + Environment.NewLine +
Util.GetTerminalDistributionString(trees) + Environment.NewLine
);
}
示例5: TownGenerator
public TownGenerator(int MaxXSearchArea, int MaxZSearchArea)
{
this._towns = new List<Town> ();
this._mt = new MersenneTwister ((uint)DateTime.Now.Ticks);
this._maxXSearchArea = MaxXSearchArea;
this._maxZSearchArea = MaxZSearchArea;
}
示例6: ProbabilisticTreeCreaterDistributionsTest
public void ProbabilisticTreeCreaterDistributionsTest() {
var randomTrees = new List<ISymbolicExpressionTree>();
var grammar = Grammars.CreateSimpleArithmeticGrammar();
var random = new MersenneTwister(31415);
var stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i < POPULATION_SIZE; i++) {
randomTrees.Add(ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_LENGTH, MAX_TREE_DEPTH));
}
stopwatch.Stop();
int count = 0;
int depth = 0;
foreach (var tree in randomTrees) {
Util.IsValid(tree);
count += tree.Length;
depth += tree.Depth;
}
double msPerRandomTreeCreation = stopwatch.ElapsedMilliseconds / (double)POPULATION_SIZE;
Console.WriteLine("ProbabilisticTreeCreator: " + Environment.NewLine +
msPerRandomTreeCreation + " ms per random tree (~" + Math.Round(1000.0 / (msPerRandomTreeCreation)) + "random trees / s)" + Environment.NewLine +
Util.GetSizeDistributionString(randomTrees, 105, 5) + Environment.NewLine +
Util.GetFunctionDistributionString(randomTrees) + Environment.NewLine +
Util.GetNumberOfSubtreesDistributionString(randomTrees) + Environment.NewLine +
Util.GetTerminalDistributionString(randomTrees) + Environment.NewLine +
"Average tree depth: " + depth / POPULATION_SIZE + Environment.NewLine +
"Average tree length: " + count / POPULATION_SIZE + Environment.NewLine +
"Total nodes created: " + count + Environment.NewLine
);
//mkommend: commented due to performance issues on the builder
// Assert.IsTrue(Math.Round(1000.0 / (msPerRandomTreeCreation)) > 250); // must achieve more than 250 random trees / s
}
示例7: Start
// Use this for initialization
void Start () {
rand = new MersenneTwister ();
spawnedMobs = new List<GameObject> ();
// set local private player object to the singleton player.
goPlayer = GameObject.FindWithTag ("Player").GetComponent<Player>();
}
示例8: RandomEnumerableProducesRangesWithUniformDistributions
public void RandomEnumerableProducesRangesWithUniformDistributions()
{
var randomSource = new MersenneTwister();
const double trials = 100000;
var zeroFrequency = Enumerable.Range(0, 10).ToDictionary(x => x, x => 0);
var fiveFrequency = Enumerable.Range(0, 10).ToDictionary(x => x, x => 0);
var nineFrequency = Enumerable.Range(0, 10).ToDictionary(x => x, x => 0);
for (var count = 0; count < trials; count++ )
{
var result = Lospi.Utils.Statistics.RandomEnumerable.Range(0, 10, randomSource);
zeroFrequency[result[0]]++;
fiveFrequency[result[5]]++;
nineFrequency[result[9]]++;
}
for (var i = 0; i < 10; i++)
{
Assert.That(zeroFrequency[i], Is.EqualTo(trials / 10D).Within(10).Percent);
Assert.That(fiveFrequency[i], Is.EqualTo(trials / 10D).Within(10).Percent);
Assert.That(nineFrequency[i], Is.EqualTo(trials / 10D).Within(10).Percent);
}
}
示例9: MyClassInitialize
public static void MyClassInitialize(TestContext testContext) {
random = new MersenneTwister();
symmetricDistances = new DoubleMatrix(ProblemSize, ProblemSize);
symmetricWeights = new DoubleMatrix(ProblemSize, ProblemSize);
asymmetricDistances = new DoubleMatrix(ProblemSize, ProblemSize);
asymmetricWeights = new DoubleMatrix(ProblemSize, ProblemSize);
nonZeroDiagonalDistances = new DoubleMatrix(ProblemSize, ProblemSize);
nonZeroDiagonalWeights = new DoubleMatrix(ProblemSize, ProblemSize);
for (int i = 0; i < ProblemSize - 1; i++) {
for (int j = i + 1; j < ProblemSize; j++) {
symmetricDistances[i, j] = random.Next(ProblemSize * 100);
symmetricDistances[j, i] = symmetricDistances[i, j];
symmetricWeights[i, j] = random.Next(ProblemSize * 100);
symmetricWeights[j, i] = symmetricWeights[i, j];
asymmetricDistances[i, j] = random.Next(ProblemSize * 100);
asymmetricDistances[j, i] = random.Next(ProblemSize * 100);
asymmetricWeights[i, j] = random.Next(ProblemSize * 100);
asymmetricWeights[j, i] = random.Next(ProblemSize * 100);
nonZeroDiagonalDistances[i, j] = random.Next(ProblemSize * 100);
nonZeroDiagonalDistances[j, i] = random.Next(ProblemSize * 100);
nonZeroDiagonalWeights[i, j] = random.Next(ProblemSize * 100);
nonZeroDiagonalWeights[j, i] = random.Next(ProblemSize * 100);
}
nonZeroDiagonalDistances[i, i] = random.Next(ProblemSize * 100);
nonZeroDiagonalWeights[i, i] = random.Next(ProblemSize * 100);
}
int index = random.Next(ProblemSize);
if (nonZeroDiagonalDistances[index, index] == 0)
nonZeroDiagonalDistances[index, index] = random.Next(1, ProblemSize * 100);
index = random.Next(ProblemSize);
if (nonZeroDiagonalWeights[index, index] == 0)
nonZeroDiagonalWeights[index, index] = random.Next(1, ProblemSize * 100);
assignment = new Permutation(PermutationTypes.Absolute, ProblemSize, random);
}
示例10: DrunkardWalk
public static int DrunkardWalk(Unit unit)
{
MersenneTwister mt = new MersenneTwister();
unit.MakeAMove((CardinalDirection)mt.Next(9));
return 100;
}
示例11: GenerateUrlCompatibleName
public static string GenerateUrlCompatibleName(int length)
{
if (length < 0)
{
throw new ArgumentOutOfRangeException("The length parameter " + "cannot be below zero!");
}
var seed = (uint)(Guid.NewGuid().GetHashCode() + (uint)Int32.MaxValue);
var result = new StringBuilder(length);
var twister = new MersenneTwister(seed);
for (int i = 0; i < length; ++i)
{
result.Append(
(char)twister.Next(Constants.BasicLatinStartSymbolNumber, Constants.BasicLatinEndSymbolNumber));
}
for (int i = Constants.BasicLatinExcludedStartSymbolNumber;
i <= Constants.BasicLatinExcludedEndSymbolNumber;
++i)
{
result.Replace(
(char)i,
(char)
twister.Next(Constants.BasicLatinStartDigitSymbolNumber, Constants.BasicLatinEndDigitSymbolNumber));
}
return result.ToString();
}
示例12: RandomString
public static string RandomString(string pattern, uint seed)
{
MersenneTwister oRandom = null;
if (seed == 0) oRandom = new MersenneTwister();
else oRandom = new MersenneTwister(seed);
return RandomString(oRandom, pattern);
}
示例13: GetIVs
public static string GetIVs(uint seed, int initialFrame, int maxFrame)
{
string ivs = "";
var rng = new MersenneTwister(seed);
rng.Nextuint();
rng.Nextuint();
for (int n = 1; n < initialFrame; n++)
{
rng.Nextuint();
}
int rngCalls = maxFrame - initialFrame;
for (int n = 0; n < rngCalls; n++)
{
uint result = rng.Nextuint();
ivs += GetIV(result);
if (n != rngCalls - 1)
{
ivs += ", ";
}
}
return ivs;
}
示例14: Randomizer
public Randomizer(string oldRomPath_, string fullSeed)
{
oldRomPath = oldRomPath_;
newRomPath = "smb3rr_" + fullSeed + ".nes";
SeparateFullSeed(fullSeed); // prngSeed and levelFlags are initialized here
mt = new MersenneTwister(prngSeed);
}
示例15: SampleKnownValues
public void SampleKnownValues()
{
var mt = new MersenneTwister(0);
Assert.AreEqual(mt.NextDouble(), 0.5488135024320365);
Assert.AreEqual(mt.NextDouble(), 0.5928446165269344);
Assert.AreEqual(mt.NextDouble(), 0.7151893651381110);
Assert.AreEqual(mt.NextDouble(), 0.8442657442866512);
}