cryptography

How can I generate a unique, small, random, and user-friendly key?

醉酒当歌 提交于 2020-08-21 03:37:08
问题 A few months back I was tasked with implementing a unique and random code for our web application. The code would have to be user friendly and as small as possible, but still be essentially random (so users couldn't easily predict the next code in the sequence). It ended up generating values that looked something like this: Af3nT5Xf2 Unfortunately, I was never satisfied with the implementation. Guid's were out of the question, they were simply too big and difficult for users to type in. I was

How can I generate a unique, small, random, and user-friendly key?

怎甘沉沦 提交于 2020-08-21 03:36:35
问题 A few months back I was tasked with implementing a unique and random code for our web application. The code would have to be user friendly and as small as possible, but still be essentially random (so users couldn't easily predict the next code in the sequence). It ended up generating values that looked something like this: Af3nT5Xf2 Unfortunately, I was never satisfied with the implementation. Guid's were out of the question, they were simply too big and difficult for users to type in. I was

Node: Generate 6 digits random number using crypto.randomBytes

喜欢而已 提交于 2020-08-18 16:29:09
问题 What is the correct way to generate exact value from 0 to 999999 randomly since 1000000 is not a power of 2? This is my approach: use crypto.randomBytes to generate 3 bytes and convert to hex use the first 5 characters to convert to integer (max is fffff == 1048575 > 999999 ) if the result > 999999 , start from step 1 again It will somehow create a recursive function. Is it logically correct and will it cause a concern of performance? 回答1: There are several way to extract random numbers in a

Node: Generate 6 digits random number using crypto.randomBytes

空扰寡人 提交于 2020-08-18 16:25:26
问题 What is the correct way to generate exact value from 0 to 999999 randomly since 1000000 is not a power of 2? This is my approach: use crypto.randomBytes to generate 3 bytes and convert to hex use the first 5 characters to convert to integer (max is fffff == 1048575 > 999999 ) if the result > 999999 , start from step 1 again It will somehow create a recursive function. Is it logically correct and will it cause a concern of performance? 回答1: There are several way to extract random numbers in a

【C#】Random类中构造方法、时间种子与随机数序列的关系

妖精的绣舞 提交于 2020-08-16 03:54:17
Random类 构造函数 1) Random random = new Random(); // 无参数构造函数使用系统时钟生成其种子值 然而, 系统时钟取值范围有限 ,因此在小规模计算中,可能无法使用不同的种子值分别调用此构造函数, 这将导致两个random对象生成相同的随机数字序列。 1 using System; 2 using System.Collections.Generic; 3 4 namespace FirstTest 5 { 6 class Program 7 { 8 static void Main( string [] args) 9 { 10 Random random1 = new Random(); 11 List< int > list1 = new List< int > (); 12 GetRandomNumbers(random1, list1); 13 Console.WriteLine( " random1对象使用默认构造函数生成的随机数序列: " ); 14 PrintList(list1); 15 16 Random random2 = new Random(); 17 List< int > list2 = new List< int > (); 18 GetRandomNumbers(random2, list2); 19