Click here to Skip to main content
15,888,984 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Create random Number Pin
Abhijit Jana9-Mar-09 3:28
professionalAbhijit Jana9-Mar-09 3:28 
GeneralRe: Create random Number Pin
scottgp9-Mar-09 5:09
professionalscottgp9-Mar-09 5:09 
GeneralRe: Create random Number Pin
Christian Graus9-Mar-09 11:09
protectorChristian Graus9-Mar-09 11:09 
AnswerRe: Create random Number Pin
N a v a n e e t h9-Mar-09 4:09
N a v a n e e t h9-Mar-09 4:09 
AnswerRe: Create random Number Pin
Jack Li9-Mar-09 4:59
Jack Li9-Mar-09 4:59 
GeneralRe: Create random Number Pin
N a v a n e e t h9-Mar-09 5:09
N a v a n e e t h9-Mar-09 5:09 
GeneralRe: Create random Number Pin
Abhishek Sur9-Mar-09 6:04
professionalAbhishek Sur9-Mar-09 6:04 
AnswerRe: Create random Number Pin
Perisic, Aleksandar9-Mar-09 7:55
Perisic, Aleksandar9-Mar-09 7:55 
You can take several approaches:

Make a list of max number of random numbers that you need and shuffle them, then go and insert one after another. A good random shuffle algorithm you can create in no time.

You could use a good hash function. There are plenty to choose. You need two keys, one is secret and somewhat random, and another is ID itself. You combine them and get a random number using the hash function. (I can give you an example of very simple and fast one if you like.)

Another is to create a circular random function which calculates a random number from the previous random value. You keep only the last entry. You take care that the cycle size is exactly what you need.

You use normal random number and check if that one is used in the database, and keep searching for the one that is not.

You can use a simple random number and attach to it your ID so that the size of both is 10 digit. For example you know you will not need more than 9999 id's. Good. Take six digit random number and concatenate to it 4 digit ID. This is not a completely random number but it is as strong as six digit random number.

You can use a matrix

  0123456789
0
1
2
3
4
5
6
7
8
9

and then use random generator mod 10 (0-9 digit at random) (or in general mod matrix size). Now ,if you would get these numbers 4, 5, 7, 0 you mark (4,5) (5,7) (7,0) and keep on until you get your first ten-digit number. For the next ten-digit number you keep on marking but you count how many entries were previously already marked. If you find for a 10 digit number that its all 9 entries were marked you reject that number. This way you get a smaller number of unique random numbers, but the matrix can always be larger (100x100...), of course.

Keep in mind what security level you need.

And do not use GUID, it is never a random number on one computer.

modified on Monday, March 9, 2009 2:02 PM

GeneralRe: Create random Number Pin
Yusuf9-Mar-09 8:20
Yusuf9-Mar-09 8:20 
GeneralRe: Create random Number [modified] Pin
Perisic, Aleksandar9-Mar-09 9:05
Perisic, Aleksandar9-Mar-09 9:05 
GeneralRe: Create random Number Pin
Yusuf9-Mar-09 10:54
Yusuf9-Mar-09 10:54 
GeneralRe: Create random Number Pin
Perisic, Aleksandar9-Mar-09 11:44
Perisic, Aleksandar9-Mar-09 11:44 
QuestionMake Browser Window Blink in Task Bar Pin
rushi_gavankar9-Mar-09 3:18
rushi_gavankar9-Mar-09 3:18 
AnswerI am pretty sure you can't do this Pin
Gregory Gadow9-Mar-09 7:12
Gregory Gadow9-Mar-09 7:12 
QuestionUpdatePanel without ScriptManager Pin
.NET- India 9-Mar-09 2:45
.NET- India 9-Mar-09 2:45 
AnswerRe: UpdatePanel without ScriptManager Pin
Abhishek Sur9-Mar-09 2:49
professionalAbhishek Sur9-Mar-09 2:49 
GeneralRe: UpdatePanel without ScriptManager Pin
Jack Li9-Mar-09 5:09
Jack Li9-Mar-09 5:09 
GeneralRe: UpdatePanel without ScriptManager Pin
Abhijit Jana9-Mar-09 6:00
professionalAbhijit Jana9-Mar-09 6:00 
AnswerRe: UpdatePanel without ScriptManager Pin
Rutvik Dave9-Mar-09 10:10
professionalRutvik Dave9-Mar-09 10:10 
QuestionUpdate a gridview row without edit Pin
foryou9-Mar-09 2:35
foryou9-Mar-09 2:35 
AnswerRe: Update a gridview row without edit Pin
Yusuf9-Mar-09 4:53
Yusuf9-Mar-09 4:53 
GeneralRe: Update a gridview row without edit Pin
foryou9-Mar-09 5:04
foryou9-Mar-09 5:04 
AnswerRe: Update a gridview row without edit Pin
kumar_k5089-Mar-09 21:58
kumar_k5089-Mar-09 21:58 
QuestionHow to execute multiple records on the Page Load Event Pin
sjs4u9-Mar-09 2:25
sjs4u9-Mar-09 2:25 
AnswerRe: How to execute multiple records on the Page Load Event Pin
Abhishek Sur9-Mar-09 2:42
professionalAbhishek Sur9-Mar-09 2:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.