using System; using System.IO; using System.Runtime.CompilerServices; using System.Security.Cryptography; namespace SmallInjectorDemo { /// /// Static helper class for generating random numbers. /// public static class Helper { /// /// Return cryptographic stable random integer. /// /// Lower border of result. /// Upper border of result. /// Random integer. public static int NewRandomInteger(int min, int max) { // The random number provider. using (var rand = new RNGCryptoServiceProvider()) { var scale = uint.MaxValue; while (scale == uint.MaxValue) { // Get four random bytes. var four_bytes = new byte[4]; rand.GetBytes(four_bytes); // Convert that into an uint. scale = BitConverter.ToUInt32(four_bytes, 0); } // Add min to the scaled difference between max and min. return (int) (min + (max - min) * (scale / (double) uint.MaxValue)); } } /// /// Write method string. /// /// id of the object /// member name /// file path /// public static string WriteMethodString(int id, [CallerMemberName] string memberName = null, [CallerFilePath] string filepath = null) { var classname = Path.GetFileNameWithoutExtension(filepath); return $"{classname}.{memberName?.TrimStart('.')}".PadRight(30) + $"Id: {id}"; } } }