using System.Security.Cryptography;
public static void Main()
Console.WriteLine(Get(8));
private const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
public static string Get(int length)
var max = chars.Length - 1;
var randomCode = new string(Enumerable.Repeat(chars, length).Select(s => s[GetRandomInteger(min, max)]).ToArray());
return "REF" + randomCode;
public static int GetRandomInteger(int min, int max)
var scale = uint.MaxValue;
var rand = new RNGCryptoServiceProvider();
while (scale == uint.MaxValue)
var four_bytes = new byte[4];
rand.GetBytes(four_bytes);
scale = BitConverter.ToUInt32(four_bytes, 0);
return (int)(min + ((max - min) * (scale / (double)uint.MaxValue)));