Click here to Skip to main content
12,827,807 members (48,283 online)
Rate this:
Please Sign up or sign in to vote.
See more: C ASP.NET
Can Anyone help me...

in my coding generating random number upto 3 digits i want from 4 digits.. what can i do for that.... and also it generate 2 times page loading & submit time..but i want only when page is load...ple help me..


public void securitykey()
       Random randobj = new Random();
       byte[] randArray = new byte[2000];
       for (int i = 0; i < randArray.Length; i++)
           Label4.Text = randArray[i].ToString();
Posted 21-Dec-11 19:24pm
Updated 12-Dec-16 20:56pm
SAKryukov 22-Dec-11 1:03am
Why do you think a security key of 4 digits could be enough? Even in hexadecimal digits, this is only a matter of trying no more than 65536 times... (Or gosh, our vulnerable, vulnerable checking accounts :-(
In security, people usually consider 1-2 Kilobytes keys as absolute minimum... How about that?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First of all, I really cannot understand why so many people do the same bad mistake all the time? The Random object should be created only once (per lifetime of the while application domain). I cannot understand what's the rationale behind that? Don't do it! At least move initialization of randobj out of the loop.

(I also cannot stop be amazed about using sub-string "obj" or "object" in the name of object, "app" or "application" in the name of application, "arr" or "array" in the name of array, etc. How can it even come to one's mind?!)

The object randArray makes no sense, whatsoever. The hard-coded immediate constant is just amazing. And the loop…

Let's say you need four decimal digits. All you need is:

Random random = new Random();
int value = random.Next(10000); //will generate a number 0 to 9999

eshitagupta 28-May-13 19:24pm
Error 56 'random' is a 'variable' but is used like a 'method' how solve that>>??
Sergey Alexandrovich Kryukov 28-May-13 19:31pm
Sorry, it was my typo. Should be of course "random.Next".
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

how to generate random number 3digits
ppolymorphe 13-Dec-16 4:02am
Open your own question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170326.1 | Last Updated 13 Dec 2016
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100