Print Page | Close Window

ASP Random Number

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=14010
Printed Date: 30 March 2026 at 3:02pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: ASP Random Number
Posted By: Gullanian
Subject: ASP Random Number
Date Posted: 26 February 2005 at 12:56am
Using this code:

            Randomize

            'Get random number
            lngRandomNumber = int(rnd*118) + 1


Problem is, the results don't seem to be random.  The code is looped 9 times, and the 9 results seem to have a predictable pattern.

Is this normal?  Any better alternative?



Replies:
Posted By: bootcom
Date Posted: 26 February 2005 at 1:30am
Originally posted by Gullanian Gullanian wrote:

Using this code:

            Randomize

            'Get random number
            lngRandomNumber = int(rnd*118) + 1


Problem is, the results don't seem to be random.  The code is looped 9 times, and the 9 results seem to have a predictable pattern.

Is this normal?  Any better alternative?
Personally, I think you should create a function to randomise the number for you ... then call as needed Big smile
 
Here's one for you to help you too Smile
 
<%
' Create a function to randomise a number
Function RandomNumber(intHighestNumber)
 Randomize
 RandomNumber = Int(intHighestNumber * Rnd) + 1
End Function
%>
 
Then call in the script
 
<%= RandomNumber("118") %>
 
Hope that helps dude.
 
Chris


Posted By: ljamal
Date Posted: 26 February 2005 at 3:03am
it's th e exact same code, just in a function

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: bootcom
Date Posted: 27 February 2005 at 9:26pm
But this works !!!!
 
Give it a go, I promise you it works.


Posted By: dj air
Date Posted: 28 February 2005 at 9:18am
this is not the exact same code or system. before

it was getting the random number and * 118  and +1

the above works as you set a different value for inthighestnumber.

this value can be anything, and so if you have a random number there it has a random output compared to the original.





Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net