Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi. Given the size of your problem, would you just want to do something
like a shuffle? Dim numsStored(1 To 6) As Long Sub Demo() Dim p As Long '(P)ointer Dim p2 As Long 'Second Pointer Dim t As Long '(t)empoary '// Load your 6 numbers... For p = 1 To 6 numsStored(p) = p Next p '// Shuffle For p = 1 To 6 p2 = Int(6 * Rnd) + 1 ' Swap... t = numsStored(p) numsStored(p) = numsStored(p2) numsStored(p2) = t Next p End Sub -- HTH. :) Dana DeLouis Windows XP, Office 2003 "msburza" wrote in message ... I have made the code working :) Code: -------------------- Option Explicit Dim numsStored(5) As Integer Dim i As Integer Dim j As Integer Dim n As Integer Dim numOk As Boolean Private Sub CommandButton1_Click() For i = 0 To 5 Do numRnd For j = 0 To i If j = 0 Then numOk = True ElseIf numsStored(i) = numsStored(i - j) Then numOk = False numRnd End If Next j Loop Until numOk = True Next i For i = 0 To 5 Cells(i + 1, 4).Value = numsStored(i) Next i End Sub Private Sub numRnd() Randomize n = Int(6 * Rnd) + 1 numsStored(i) = n End Sub -------------------- -- msburza ------------------------------------------------------------------------ msburza's Profile: http://www.excelforum.com/member.php...o&userid=34222 View this thread: http://www.excelforum.com/showthread...hreadid=539800 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Generate random numbers 1-100 without any repeats? | Excel Worksheet Functions | |||
generating random numbers without repeats | Excel Discussion (Misc queries) | |||
Random Code Generation | Excel Worksheet Functions | |||
Random number generation - with no repeats | Excel Discussion (Misc queries) | |||
Random numbers generation | Excel Programming |