本文整理汇总了C#中MersenneTwister类的典型用法代码示例。如果您正苦于以下问题:C# MersenneTwister类的具体用法?C# MersenneTwister怎么用?C# MersenneTwister使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MersenneTwister类属于命名空间,在下文中一共展示了MersenneTwister类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:CoderBear,项目名称:AAUnity,代码行数:8,代码来源:PRNG.cs
示例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;
}
开发者ID:CaptBrick,项目名称:ZExtensions,代码行数:7,代码来源:MersenneTwister.cs
示例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);
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:34,代码来源:GradientBoostedTreesAlgorithmStatic.cs
示例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
);
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:27,代码来源:ArgumentCreaterTest.cs
示例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;
}
开发者ID:bobtwinkles,项目名称:RPGGen,代码行数:7,代码来源:TownGenerator.cs
示例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
}
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:33,代码来源:ProbabilisticTreeCreaterTest.cs
示例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>();
}
开发者ID:CoderBear,项目名称:ARG-Zombies,代码行数:8,代码来源:enterCombat.cs
示例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);
}
}
开发者ID:JLospinoso,项目名称:lut,代码行数:29,代码来源:RandomEnumerableTest.cs
示例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);
}
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:34,代码来源:QAPMoveEvaluatorTest.cs
示例10: DrunkardWalk
public static int DrunkardWalk(Unit unit)
{
MersenneTwister mt = new MersenneTwister();
unit.MakeAMove((CardinalDirection)mt.Next(9));
return 100;
}
开发者ID:scienide00,项目名称:MayaRoguelike,代码行数:7,代码来源:AI.cs
示例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();
}
开发者ID:RamanBut-Husaim,项目名称:TermWork-SignalRChat,代码行数:28,代码来源:CryptoHelper.cs
示例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);
}
开发者ID:kLeZ,项目名称:Gecko,代码行数:7,代码来源:Randomizer.cs
示例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;
}
开发者ID:Slashmolder,项目名称:RNGReporter,代码行数:29,代码来源:Gen5IVs.cs
示例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);
}
开发者ID:CujoIHSV,项目名称:SMB3RR,代码行数:8,代码来源:Randomizer.cs
示例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);
}
开发者ID:KeithVanderzanden,项目名称:mmbot,代码行数:8,代码来源:MersenneTwisterTests.cs
示例16: SampleKnownValues
public void SampleKnownValues()
{
var mt = new MersenneTwister(0);
Assert.AreEqual(mt.NextDouble(), 0.5488135023042560);
Assert.AreEqual(mt.NextDouble(), 0.5928446163889021);
Assert.AreEqual(mt.NextDouble(), 0.7151893649715930);
Assert.AreEqual(mt.NextDouble(), 0.8442657440900803);
}
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:8,代码来源:MersenneTwisterTests.cs
示例17: GridSearch
private static RandomForestRegressionSolution GridSearch(IRegressionProblemData problemData, out RFParameter bestParameters, int seed = 3141519) {
double rmsError, outOfBagRmsError, avgRelError, outOfBagAvgRelError;
var random = new MersenneTwister();
bestParameters = RandomForestUtil.GridSearch(problemData, randomForestParameterRanges, seed, maximumDegreeOfParallelism);
var model = RandomForestModel.CreateRegressionModel(problemData, problemData.TrainingIndices, bestParameters.N, bestParameters.R, bestParameters.M, seed,
out rmsError, out outOfBagRmsError, out avgRelError, out outOfBagAvgRelError);
return (RandomForestRegressionSolution)model.CreateRegressionSolution(problemData);
}
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:8,代码来源:GridSearchRFRegressionScriptSource.cs
示例18: ProbabilisticTreeCreatorSpecificTreeSizesTest
public void ProbabilisticTreeCreatorSpecificTreeSizesTest() {
var grammar = Grammars.CreateSimpleArithmeticGrammar();
var random = new MersenneTwister(31415);
for (int targetTreeSize = 3; targetTreeSize <= 100; targetTreeSize++) {
var tree = ProbabilisticTreeCreator.CreateExpressionTree(random, grammar, targetTreeSize, ((int)Math.Log(targetTreeSize, 2)) + 2);
Assert.AreEqual(targetTreeSize, tree.Length);
}
}
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:9,代码来源:ProbabilisticTreeCreatorTest.cs
示例19: MakeValid
public HSLColor MakeValid(Color askedColor, MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors, Action<string> onError)
{
Color forbiddenColor;
if (IsValid(askedColor, out forbiddenColor, terrainColors, playerColors, onError))
return new HSLColor(askedColor);
// Vector between the 2 colors
var vector = new double[]
{
askedColor.R - forbiddenColor.R,
askedColor.G - forbiddenColor.G,
askedColor.B - forbiddenColor.B
};
// Reduce vector by it's biggest value (more calculations, but more accuracy too)
var vectorMax = vector.Max(vv => Math.Abs(vv));
if (vectorMax == 0)
vectorMax = 1; // Avoid division by 0
vector[0] /= vectorMax;
vector[1] /= vectorMax;
vector[2] /= vectorMax;
// Color weights
var rmean = (double)(askedColor.R + forbiddenColor.R) / 2;
var weightVector = new[]
{
2.0 + rmean / 256,
4.0,
2.0 + (255 - rmean) / 256,
};
var attempt = 1;
var allForbidden = terrainColors.Concat(playerColors);
HSLColor color;
do
{
// If we reached the limit (The ii >= 255 prevents too much calculations)
if (attempt >= 255)
{
color = RandomValidColor(random, terrainColors, playerColors);
break;
}
// Apply vector to forbidden color
var r = (forbiddenColor.R + (int)(vector[0] * weightVector[0] * attempt)).Clamp(0, 255);
var g = (forbiddenColor.G + (int)(vector[1] * weightVector[1] * attempt)).Clamp(0, 255);
var b = (forbiddenColor.B + (int)(vector[2] * weightVector[2] * attempt)).Clamp(0, 255);
// Get the alternative color attempt
color = new HSLColor(Color.FromArgb(r, g, b));
attempt++;
} while (!IsValid(color.RGB, allForbidden, out forbiddenColor));
return color;
}
开发者ID:CH4Code,项目名称:OpenRA,代码行数:57,代码来源:ColorValidator.cs
示例20: SampleSelecter
protected SampleSelecter()
{
if (rand == null)
{
uint seed = (uint)Math.Abs(DateTime.Now.Ticks);//TODO test edge cases on seed value
rand = new MersenneTwister(seed);
}
this.Count = 0;
}
开发者ID:FMSC-Measurements,项目名称:FMSC.Sampling,代码行数:9,代码来源:SampleSelecter.cs
注:本文中的MersenneTwister类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论