?
Solved

Rnd() values are changing everytime in ASP.NET

Posted on 2006-10-20
16
Medium Priority
?
27,931 Views
Last Modified: 2012-06-22
hi all,

IntTemp = Int((255 * Rnd()) + 1)

I used above ASP.NET code. Problem is in " Rnd() " 
Rnd() value is changing everytime.

What is the alternative for Rnd()? OR How will stop Rnd() value changes at everytime?

Thanks
0
Comment
Question by:genesiscircle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +4
16 Comments
 
LVL 6

Expert Comment

by:bigphuckinglizard
ID: 17772692
change the 255 to a 0 and you'll get the same number each time.
0
 
LVL 10

Expert Comment

by:gangwisch
ID: 17773467
rnd is a function for producing a random value
0
 
LVL 16

Expert Comment

by:OliWarner
ID: 17774275
>> Rnd() values are changing everytime in ASP.NET

As gangwisch said, Rnd() gives a random number... Why would you expect a random number to stay the same?

ROFL@ bigphuckinglizard's answer =)
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

Expert Comment

by:Jivlain
ID: 17841507
Rnd() is a function for producing a value, as OliWarner said.

Each time you call the Rnd() function you will get a different value.
However, you can get the numbers to come out in the same order each time by calling

Try this:

Randomize(25) 'whatever number here will affect which set of numbers will come up
for i=0 to 10
 Response.Write rnd(100).ToString()+"<br>" 'print a number between 0-99
next

Now note I haven't actually tested this... but theoretically it should print 10 numbers to the page. They'll all (probably) be different. But the same 10 should come up each time.

Gosh, it's been a very long time since I've used VB ;)
0
 

Expert Comment

by:Jivlain
ID: 17848755
Hmmmm, I've actually tested this version...

Randomize(25) 'whatever number here will affect which set of numbers will come up
Dim i As Integer
For i = 0 To 10
     Response.Write(CInt(Rnd() * 100).ToString()+"<br>") 'print a number between 0-99
Next

If you actually wanted to round a number, use CInt(x)
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 18022926
Interesting addition: this question made it to the Daily WTF. See also http://thedailywtf.com/forums/thread/103463.aspx

Doesn't seem that fair to me though. When testing an application, you might want to set a starting seed for the random numbers so you can predict which number will be next. Therefore I think Jivlain gave a correct answer to a perfectly valid question.
0
 
LVL 1

Expert Comment

by:simon_thwaites
ID: 18044502
Try this function

Function UnRnd()
UnRnd = 4 'my favourite number!
End Function

IntTemp = Int((255 * UnRnd()) + 1)
0
 
LVL 16

Expert Comment

by:OliWarner
ID: 18044554
Yeah 4 is a good number

Recommend simon_thwaites for the points =)
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 18700336
I'd just suggest to delete this Q because the question is just too dumb. :-) Seems to me that whomever asked it wasn't even serious. (Else he needs another job.)
0
 
LVL 16

Expert Comment

by:OliWarner
ID: 18700376
Very much agreed. This thread is just too silly.

Suggestion: Move it to the lounge for more silliness to ensue or delete it.
0
 

Accepted Solution

by:
Jivlain earned 750 total points
ID: 18706506
Aw, come on. I'm sure I could use the points for something ;)

Even if I did come to this thread off The Daily WTF.

Though it is a shame that Simon's alternate function didn't take advantage of the golden opportunity to include the number "42".
0
 
LVL 1

Expert Comment

by:fahadsadah
ID: 23498846
0
 
LVL 1

Expert Comment

by:simon_thwaites
ID: 23735456
Jivlain,

but 42 isn't my favourite number ;)

Try the AnswertoLifetheUniverseandEverything() function, but it does take 7.5 Million years to execute, damn Java... they should have used C or something...
0

Featured Post

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question