using System;
using System.Security.Cryptography;
using System.IO;
public class Test
{
static Int64 Key;
static Random Rand = new Random();
public static byte[] Encrypt(byte[] ClearData, byte[] Key)
{
MemoryStream ms = new MemoryStream();
Rijndael alg = Rijndael.Create();
alg.KeySize = 128;
alg.BlockSize = 128;
alg.Mode = CipherMode.ECB;
alg.Key = Key;
CryptoStream cs = new CryptoStream(ms, alg.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(ClearData, 0, ClearData.Length);
cs.Close();
byte[] encryptedData = ms.ToArray();
return encryptedData;
}
public static int RandomValue(int Max)
{
byte[] FirstHalf = BitConverter.GetBytes(Key);
byte[] SecondHalf = BitConverter.GetBytes(Key);
byte[] KeyBytes = new Byte[FirstHalf.Length + SecondHalf.Length];
FirstHalf.CopyTo(KeyBytes, 0);
SecondHalf.CopyTo(KeyBytes, FirstHalf.Length);
byte[] RandValue = Encrypt(new byte[0], KeyBytes);
int Rand = Math.Abs(BitConverter.ToInt32(RandValue, 0));
return Rand % Max;
}
public static int NextValue(int Max)
{
++Key;
return RandomValue(Max);
}
public static int PreviousValue(int Max)
{
--Key;
return RandomValue(Max);
}
public static void Main()
{
//Init key
byte[] buffer = new byte[sizeof(Int64)];
Rand.NextBytes(buffer);
Key = BitConverter.ToInt64(buffer, 0);
for(int i = 0 ; i < 4 ; ++i)
{
Console.WriteLine(NextValue(10));
}
Console.WriteLine();
for(int i = 0 ; i < 4 ; ++i)
{
Console.WriteLine(PreviousValue(10));
}
}
}