protected void trigger() { try { DataSet ds = ExamManagement.SP.Questionpaper_SP_Selectall().GetDataSet(); if (ds.Tables[0].Rows.Count > 0) { string a = RandomNumberGenerator(4); string b = RandomNumberGenerator(4); string c = RandomNumberGenerator(4); ExamManagement.SP.Passkey_insert(a, b, c).Execute(); } } catch { throw; **// Exception Was Thrown Here** } } public static string RandomNumberGenerator(int length) { System.Security.Cryptography.RandomNumberGenerator rng = System.Security.Cryptography.RandomNumberGenerator.Create(); char[] chars = new char[length]; //based on your requirment you can take only alphabets or number string validChars = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXzZ"; for (int i = 0; i < length; i++) { byte[] bytes = new byte[1]; rng.GetBytes(bytes); Random rnd = new Random(bytes[0]); chars[i] = validChars[rnd.Next(0, 61)]; } return (new string(chars)); }
validChars
string
chars[i] = validChars[rnd.Next(validChars.Length)];
byte[] bytes = new byte[length-1]; for (int i = 0; i < length; i++) { rng.GetBytes(bytes); Random rnd = new Random(bytes[0]); chars[i] = validChars[rnd.Next(0, 61)]; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)