Click here to Skip to main content
15,912,977 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: How to Upload Directory Pin
ZurdoDev29-Jul-14 10:20
professionalZurdoDev29-Jul-14 10:20 
AnswerRe: How to Upload Directory Pin
meeram3929-Jul-14 18:31
professionalmeeram3929-Jul-14 18:31 
AnswerRe: How to Upload Directory Pin
jkirkerx30-Jul-14 10:05
professionaljkirkerx30-Jul-14 10:05 
AnswerRe: How to Upload Directory Pin
Nathan Minier1-Aug-14 4:04
professionalNathan Minier1-Aug-14 4:04 
QuestionRandom 8 digit number Pin
byka28-Jul-14 4:55
byka28-Jul-14 4:55 
AnswerRe: Random 8 digit number Pin
Richard Deeming28-Jul-14 5:26
mveRichard Deeming28-Jul-14 5:26 
GeneralRe: Random 8 digit number Pin
byka28-Jul-14 5:51
byka28-Jul-14 5:51 
GeneralRe: Random 8 digit number Pin
Richard Deeming28-Jul-14 6:12
mveRichard Deeming28-Jul-14 6:12 
So call the parameterless constructor of the Random class. That uses the Environment.TickCount as the seed. Since there are 10000 ticks in a millisecond, you'll be less likely to get repeated numbers.

If that's still not random enough, or you're using the random numbers for any security-related purposes, then use the System.Security.Cryptography.RandomNumberGenerator class[^] instead.
VB.NET
Public Shared Function NextRandomNumber(ByVal minValue As Integer, ByVal maxValue As Integer) As Integer
    Using random As RandomNumberGenerator = RandomNumberGenerator.Create()
        Dim b(3) As Byte
        random.GetBytes(b)
        
        Dim d As Double = CDbl(BitConverter.ToUInt32(b, 0)) / UInt32.MaxValue
        Return CInt(Math.Floor(d * maxValue - minValue) + minValue)
    End Using
End Function


See this[^] for details, including my changes in the comments.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Random 8 digit number Pin
byka28-Jul-14 6:20
byka28-Jul-14 6:20 
GeneralRe: Random 8 digit number Pin
Richard Deeming28-Jul-14 6:22
mveRichard Deeming28-Jul-14 6:22 
GeneralRe: Random 8 digit number Pin
byka29-Jul-14 1:51
byka29-Jul-14 1:51 
GeneralRe: Random 8 digit number Pin
byka29-Jul-14 1:53
byka29-Jul-14 1:53 
GeneralRe: Random 8 digit number Pin
Richard Deeming29-Jul-14 2:14
mveRichard Deeming29-Jul-14 2:14 
GeneralRe: Random 8 digit number Pin
byka29-Jul-14 2:31
byka29-Jul-14 2:31 
GeneralRe: Random 8 digit number Pin
Richard Deeming29-Jul-14 5:56
mveRichard Deeming29-Jul-14 5:56 
QuestionHow to create ASP.NET database driven dynamic website, Database Connection, Tutorial Pin
Biplob Singha Shee28-Jul-14 2:01
Biplob Singha Shee28-Jul-14 2:01 
SuggestionRe: How to create ASP.NET database driven dynamic website, Database Connection, Tutorial Pin
Richard Deeming28-Jul-14 2:50
mveRichard Deeming28-Jul-14 2:50 
GeneralRe: How to create ASP.NET database driven dynamic website, Database Connection, Tutorial Pin
Biplob Singha Shee28-Jul-14 3:20
Biplob Singha Shee28-Jul-14 3:20 
GeneralRe: How to create ASP.NET database driven dynamic website, Database Connection, Tutorial Pin
Richard Deeming28-Jul-14 3:46
mveRichard Deeming28-Jul-14 3:46 
QuestionWeb Crawling Pin
JaypalSinh9026-Jul-14 19:56
JaypalSinh9026-Jul-14 19:56 
AnswerRe: Web Crawling Pin
Kornfeld Eliyahu Peter26-Jul-14 20:33
professionalKornfeld Eliyahu Peter26-Jul-14 20:33 
GeneralRe: Web Crawling Pin
Sibeesh KV29-Sep-14 1:47
professionalSibeesh KV29-Sep-14 1:47 
GeneralRe: Web Crawling Pin
Kornfeld Eliyahu Peter29-Sep-14 2:08
professionalKornfeld Eliyahu Peter29-Sep-14 2:08 
GeneralRe: Web Crawling Pin
Sibeesh KV29-Sep-14 2:12
professionalSibeesh KV29-Sep-14 2:12 
Questionasp.net Pin
naralasaimanoj25-Jul-14 6:20
naralasaimanoj25-Jul-14 6:20 

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.