View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
msburza msburza is offline
external usenet poster
 
Posts: 1
Default code not working properly - VBA beginner (random numbers generation, no repeats)


I'm trying to write a code that will generate random numbers and no
number appears more than onece.



Code:
--------------------

For I = 0 To 3
For J = 0 To I
Do
n = Int(4 * Rnd) + 1 'random number generated
Array1(I) = n 'random number settled in an array
If (I = I - J) Then 'checking for the same place in array
numsOK = True
Else
If Array1(I) = Array1(I - J) Then 'comparing two different places in an array
numsOK = False
Else
numsOK = True
End If
End If

Loop Until numsOK = True
Next J 'only the last number and the first one always differ, other numbers repeat


--------------------

Next I Plz help me and tell why the program isnt working. I have no
idea, how to make it work.


--
msburza
------------------------------------------------------------------------
msburza's Profile: http://www.excelforum.com/member.php...o&userid=34222
View this thread: http://www.excelforum.com/showthread...hreadid=539800