Initial commit
This commit is contained in:
commit
5584446828
37 changed files with 7962 additions and 0 deletions
35
Shared/RandomNumbers.cs
Normal file
35
Shared/RandomNumbers.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Secucore
|
||||
*
|
||||
* Copyright (C) 2023 Trevor Hall
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license.
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Security.Cryptography;
|
||||
using System;
|
||||
|
||||
namespace SecuCore.Shared
|
||||
{
|
||||
class RandomNumbers
|
||||
{
|
||||
public static ushort GetNext16()
|
||||
{
|
||||
byte[] ib = RandomNumberGenerator.GetBytes(2);
|
||||
return BitConverter.ToUInt16(ib);
|
||||
}
|
||||
public static int GetNext(int min, int max)
|
||||
{
|
||||
byte[] ib = RandomNumberGenerator.GetBytes(4);
|
||||
int ival = BitConverter.ToInt32(ib, 0);
|
||||
ival = (ival >= 0 ? ival : -ival);
|
||||
int ceil = max + 1;
|
||||
int diff = ceil - min;
|
||||
int rn = ival % diff;
|
||||
return min + rn;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue