Random help

1. Member
Join Date
Dec 1969
Posts
71

## Random help

Can anyone pls help me to look at the following code? I&#039m trying to randomly pick up 5 different numbers, but there have some problem with comparing the num..it sometimes can catched the duplicated num but sometimes does.. can anyone tell me why?<BR><BR>Thanks<BR>Frankie<BR>&#060;%<BR>Dim rndMax<BR>rndMax=11<BR><BR>Dim rndNumber<BR>Randomize Timer<BR>rndNumber = Int(RND * rndMax)<BR> <BR>dim num(5)<BR>dim i<BR>i=0<BR>do until counter = 5<BR> n=int(rnd * 11)<BR> t=1<BR> if n &#062; 0 and n &#060; 12 then<BR> count2=1<BR> for count2=1 to 5 <BR> if n = num(count2) then<BR> response.write "<BR> Duplicated: " & n & num(count2) t=0<BR> exit for <BR> end if <BR> next<BR> if t=1 then<BR> num(counter)=n<BR> response.write " &nbsp;" & num(counter)<BR> counter=counter+1 <BR> end if<BR> end if<BR>loop<BR><BR>response.write ".....<BR>"<BR>for i=0 to ubound(num)<BR> response.write num(i) & " "<BR>next<BR>response.write "<BR>"<BR>%&#062;

2. Senior Member
Join Date
Dec 1969
Posts
511

## RE: Random help

Your not using rndNumber at all, but thats not a problem. You might want to set counter to 0 before the loop its used in and set all the elements in your num array to -1 or something so it knows its an array of numbers. I sometimes have a simular problem where its just not evaluating the numbers right. I got around this by using the Fix function on the numbers I was testing against. Its seems to work.<BR><BR>If 2 &#060; Fix(MyVar) Then<BR>...<BR>End If<BR><BR>Hope that helps<BR><BR>Pete

#### Posting Permissions

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