Hi there,

i have a sample aspx page, and my 2 users from different location are accessing the page at same time. On this page i did a response.write

sPrintString = sName & "_" & DateTime.Now.ToString("yyyyMMddHHmmssffffff") & "_" & objRandom.Next(1000, 999999) & "_" & objRandom.Next(1000, 999999)


Sometimes it happens that both of my users are getting the exactly same value in response.
And i think the random generated will be new every time as the objRandom var is local on that page.

Can you tell me how it is possible that same random number is generated for both users.

Thanks in advance
gbhatnagar :-)

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

7 Years
Discussion Span
Last Post by Ramesh S

Do not call the Random.Next twice in the same statement.

Try something link this.

Dim objRandom As Random = New Random()
        Dim n1 As Int32 = objRandom.Next(1000, 999999)
        Dim n2 As Int32 = objRandom.Next(1000, 999999)
        sPrintString = sName & "_" & DateTime.Now.ToString("yyyyMMddHHmmssffffff") & "_" & n1.ToString() & "_" & n2.ToString()

If you still getting the same error, try the static class approach specified in this link.

Edited by Ramesh S: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.