generate nos * uniquely * from 1 to 5 randomly

# Thread: generate nos * uniquely * from 1 to 5 randomly

1. Senior Member
Join Date
Dec 1969
Posts
128

## generate nos * uniquely * from 1 to 5 randomly

whats the simplest way to generate nos from 1 to 5 randomly. each time i refresh the screen all the 5 numbers must appear in different order

2. New ASP Guest

## RE: generate nos * uniquely * from 1 to 5 randomly

Randomize &#039; Initialize random-number generator.<BR>FOR i = 0 TO 4<BR>response.write Int((5 * Rnd) + 1) & "<BR>"<BR>NEXT

3. Senior Member
Join Date
Dec 1969
Posts
142

## RE: generate nos * uniquely * from 1 to 5 randomly

You might have to tweak this a bit, ripped it out of some of my older code... do your var declarations, etc..<BR><BR>&#060;%<BR>Function dupcheck(myarray,newnum, maxs)<BR>dim ctr2, exists<BR>exists=TRUE<BR><BR>for ctr2=0 to maxs<BR> if myarray(ctr2)=newnum Then<BR> exists=FALSE<BR> end if<BR>next<BR>dupcheck=exists<BR>End Function<BR>%&#062;<BR><BR>&#060;%<BR>Response.Wri te "Distinct Random Numbers<BR>"<BR>ctr=0<BR><BR>Do While ctr &#060; 5<BR><BR>&#039; For table spacing...<BR>if (ctr Mod cols = 0 And ctr &#060;&#062; 0) Then<BR>Response.Write "&#060;/TR&#062;&#060;TR align=&#039;center&#039;&#062;"<BR>end if<BR><BR>lower=1<BR>upper=5<BR>num=Int((upper - lower + 1) * rnd() + lower)<BR><BR>if (dupcheck(myArray,num,ctr)) then<BR>Response.Write "&#060;TD width=&#039;1%&#039;&#062;" & num & "&#060;/TD&#062;"<BR>myArray(ctr)=num<BR>ctr=ctr+1<BR>end if<BR><BR>Loop

#### Posting Permissions

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