---
lang: ja-jp
breaks: true
---
# C# プリミティブ型 毎にランダム値を取得する .NET Core 2021-09-26
```csharp=
public class RandomPrimitiveNumber
{
Random rand = null;
public RandomPrimitiveNumber()
{
rand = new System.Random();
}
public long Long()
{
long ret = rand.NextInt64(long.MinValue, long.MaxValue);
return ret;
}
public ulong ULong()
{
ulong ret = (ulong)rand.NextInt64(0, long.MaxValue);
return ret;
}
public decimal Decimal()
{
double ret = rand.NextInt64(long.MinValue, long.MaxValue) + rand.NextDouble();
decimal dec = new decimal(ret);
return dec;
}
public int Int()
{
int ret = rand.Next(int.MinValue, int.MaxValue);
//Debug.WriteLine(ret);
return ret;
}
public uint UInt()
{
uint ret = (uint)rand.NextInt64(uint.MinValue, uint.MaxValue);
return ret;
}
public nuint NUInt()
{
nuint ret = 0;
if (Environment.Is64BitProcess)
{
ret = (nuint)rand.NextInt64(uint.MinValue, uint.MaxValue);
}
else
{
ret = (nuint)rand.Next(int.MinValue, int.MaxValue);
}
return ret;
}
public short Short()
{
int ret = rand.Next(short.MinValue, short.MaxValue);
return (short)ret;
}
public ushort UShort()
{
int ret = rand.Next(ushort.MinValue, ushort.MaxValue);
return (ushort)ret;
}
public sbyte SByte()
{
int ret = rand.Next(sbyte.MinValue, sbyte.MaxValue);
return (sbyte)ret;
}
public byte Byte()
{
int ret = rand.Next(byte.MinValue, byte.MaxValue);
return (byte)ret;
}
public char Char()
{
int ret = rand.Next(byte.MinValue, byte.MaxValue);
return (char)((byte)ret);
}
public bool Bool()
{
int ret = rand.Next(0, 2);
return ret == 1 ? true : false;
}
public double Double()
{
double ret = rand.NextInt64(long.MinValue, long.MaxValue) + rand.NextDouble();
return ret;
}
public double Float()
{
float ret = rand.NextSingle();
return ret;
}
public System.Single Single()
{
System.Single ret = rand.NextSingle();
return ret;
}
}
```
###### tags: `C#` `プリミティブ型` `ランダム` `.NET Core`