generate random numbers as floats

as they get converted from double before use anyway
This commit is contained in:
Matthias Mailänder
2013-03-01 10:53:41 +01:00
parent 793dfa5748
commit 47075e1cd0
5 changed files with 5 additions and 5 deletions

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Thirdparty
public int Next(int low, int high) { return low + Next() % (high - low); }
public int Next(int high) { return Next() % high; }
public double NextDouble() { return Math.Abs(Next() / (double)0x7fffffff); }
public float NextFloat() { return Math.Abs(Next() / (float)0x7fffffff); }
void Generate()
{

View File

@@ -127,7 +127,7 @@ namespace OpenRA
public static float Gauss1D(this Thirdparty.Random r, int samples)
{
return Exts.MakeArray(samples, _ => (float)r.NextDouble() * 2 - 1f)
return Exts.MakeArray(samples, _ => r.NextFloat() * 2 - 1f)
.Sum() / samples;
}

View File

@@ -107,7 +107,7 @@ namespace OpenRA.Mods.RA
{
var info = self.Info.Traits.Get<AttackBaseInfo>();
nextScanTime = (int)(25 * (info.ScanTimeAverage +
(self.World.SharedRandom.NextDouble() * 2 - 1) * info.ScanTimeSpread));
(self.World.SharedRandom.NextFloat() * 2 - 1) * info.ScanTimeSpread));
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, (int)(Game.CellSize * range));

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA
void SpawnCrate(Actor self)
{
var inWater = self.World.SharedRandom.NextDouble() < Info.WaterChance;
var inWater = self.World.SharedRandom.NextFloat() < Info.WaterChance;
var pp = ChooseDropCell(self, inWater, 100);
if (pp == null) return;

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA
void SpawnCrate(Actor self, CrateSpawnerInfo info)
{
var threshold = 100;
var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance;
var inWater = self.World.SharedRandom.NextFloat() < info.WaterChance;
for (var n = 0; n < threshold; n++ )
{