Here are the examples of the csharp api System.Random.NextInt32() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
19
Source : PriceRangeExtensions.cs
with Apache License 2.0
from Aaronontheweb
with Apache License 2.0
from Aaronontheweb
public static decimal NextDecimalSample(this Random random)
{
var sample = 1m;
//After ~200 million tries this never took more than one attempt but it is possible to generate combinations of a, b, and c with the approach below resulting in a sample >= 1.
while (sample >= 1)
{
var a = random.NextInt32();
var b = random.NextInt32();
//The high bits of 0.9999999999999999999999999999m are 542101086.
var c = random.Next(542101087);
sample = new decimal(a, b, c, false, 28);
}
return sample;
}
19
Source : RandomExtensions.cs
with MIT License
from dotnet-toolbelt
with MIT License
from dotnet-toolbelt
public static decimal NextDecimal(this Random @this, bool sign)
{
var scale = (byte)@this.Next(29);
return new decimal(@this.NextInt32(),
@this.NextInt32(),
@this.NextInt32(),
sign,
scale);
}
19
Source : RandomizerBase.cs
with MIT License
from emrecaglar
with MIT License
from emrecaglar
public static decimal NextDecimal(this Random rng)
{
byte scale = (byte)rng.Next(29);
bool sign = rng.Next(2) == 1;
return new decimal(rng.NextInt32(),
rng.NextInt32(),
rng.NextInt32(),
sign,
scale);
}