add random number generator helper extension methods

This commit is contained in:
Gered 2013-09-07 14:18:08 -04:00
parent 5a7532a598
commit 4ef2082971
2 changed files with 34 additions and 0 deletions

View file

@ -228,6 +228,7 @@
<Compile Include="Graphics\EulerPerspectiveCamera.cs" /> <Compile Include="Graphics\EulerPerspectiveCamera.cs" />
<Compile Include="Graphics\Helpers\SkyBox.cs" /> <Compile Include="Graphics\Helpers\SkyBox.cs" />
<Compile Include="Graphics\Atlas\Json\JsonTextureAtlasAnimation.cs" /> <Compile Include="Graphics\Atlas\Json\JsonTextureAtlasAnimation.cs" />
<Compile Include="Math\RandomExtensions.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup> <ItemGroup>

View file

@ -0,0 +1,33 @@
using System;
namespace Blarg.GameFramework
{
public static class RandomExtensions
{
public static float NextFloat(this Random random)
{
return (float)random.NextDouble();
}
public static float NextFloat(this Random random, float maxValue)
{
return ((float)random.NextDouble()) * maxValue;
}
public static float NextFloat(this Random random, float minValue, float maxValue)
{
return ((float)random.NextDouble()) * (maxValue - minValue) + minValue;
}
public static double NextDouble(this Random random, double maxValue)
{
return random.NextDouble() * maxValue;
}
public static double NextDouble(this Random random, double minValue, double maxValue)
{
return random.NextDouble() * (maxValue - minValue) + minValue;
}
}
}