Random number generator

1. Senior Member
Join Date
Dec 1969
Posts
450

## Random number generator

why does only return a number starting with 1******* everytime? I need it to range from 10000000 to 99999999<BR><BR>Any takers on helping me?<BR><BR>&#060;% FUNCTION RANDOM %&#062;<BR>&#060;% DIM intLow &#039; declare lowest number variable %&#062;<BR>&#060;% DIM intHigh &#039; declare highest number variable %&#062;<BR>&#060;% RANDOMIZE TIMER %&#062;<BR>&#060;% intLow = 1000000 &#039; set lowest number variable %&#062;<BR>&#060;% intHigh = 9999999 &#039; set highest number variable %&#062;<BR>&#060;%= FormatNumber(Int((intHigh - intLow + 1) * RND + intHigh),0,0,0,0) %&#062; <BR>&#060;% END FUNCTION %&#062;

2. Senior Member
Join Date
Dec 1969
Location
Indianapolis, IN
Posts
1,755

## It works for me.

How are you calling your random function? Show that code.

3. Senior Member
Join Date
Dec 1969
Location
Indianapolis, IN
Posts
1,755

## BTW...

I think you want to do this on your last line:<BR>&#060;%= FormatNumber(Int((intHigh - intLow + 1) * RND + intLow),0,0,0,0) %&#062;<BR>instead of adding intHigh in again. As you currently have it, your numbers are going to be over 10,000,000, which you don&#039;t want.

4. Senior Member
Join Date
Dec 1969
Posts
450

## Thanks... it just always outputs a number starting

yhyy

5. Senior Member
Join Date
Dec 1969
Posts
3,195

## If it helps this is a random

function that I have used in the past and I just added your numbers for the limits.<BR><BR><BR>Function getRandomNum()<BR> dim intulimit,intllimit<BR> dim intRanNum<BR><BR> &#039;***SET UPPER AND LOWER LIMITS FOR RANGE OF NUMBERS TO RANDOMIZE<BR> intllimit = 1000000<BR> intulimit = 9999999<BR><BR> Randomize<BR> intRanNum=Int((intulimit - intllimit + 1) * Rnd() + intllimit) <BR> <BR> getRandomNum = intRanNum<BR> <BR>End Function<BR><BR>You can do a quick test like<BR><BR>for i = 1 to 100<BR> response.write getRandomNum()&"<BR>"<BR>next<BR><BR>Or change it to 1000, etc.<BR><BR>Also, in your code why all the context switching (&#060;% %&#062;)?<BR><BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
450

## Thanks... ---> explanation

It was one of the first things I ever wrote it ASP... It&#039;s in the library and usually just delete it out after I insert... kind of a reminder where I&#039;ve come from in a year....

7. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Why not?

&#062;Also, in your code why all the context switching (&#060;% %&#062;)?<BR><BR>It&#039;s faster.<BR><BR>And IMO, it&#039;s more readable.

8. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Oh, nevermind me. (eop)

.

9. Senior Member
Join Date
Dec 1969
Posts
3,195

&#060;% FUNCTION RANDOM %&#062; <BR>&#060;% DIM intLow &#039; declare lowest number variable %&#062; <BR>&#060;% DIM intHigh &#039; declare highest number variable %&#062; <BR>etc....<BR><BR>than<BR><BR>&#060;% <BR>FUNCTION RANDOM <BR> DIM intLow &#039; declare lowest number variable <BR> DIM intHigh &#039; declare highest number variable <BR> RANDOMIZE TIMER <BR> intLow = 1000000 &#039; set lowest number variable<BR>etc...<BR><BR>??<BR><BR>I guess its all relative, however IMHO I don&#039;t agree. ; )<BR><BR>Pete <BR><BR>

10. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## You're VERY right.

I posted before I reviewed his original post.<BR><BR>You&#039;re absolutely correct.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•