Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I need VB code to Randomly generat numbers from 1 to 52. Can anybody
help? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
Try this : Dim MyValue Sub Random() MyValue = Int((52 * Rnd) + 1) ' Generate random value between 1 and 52. End Sub Jason " wrote: I need VB code to Randomly generat numbers from 1 to 52. Can anybody help? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
num = int(rnd()*52+1)
Are you trying to shuffle a card deck? Sub Shuffle() ' ' Algorithm from: ' The Art of Computer Programming: _ ' SemiNumerical Algorithms Vol 2, 2nd Ed. ' Donald Knuth ' p. 139 [Algorithm P] ' ' Dim list As Variant Dim rng As Range Dim t As Long, j As Long, k As Long For j = 1 To 52 Cells(j, 1) = j Next j Set rng = Range("A1:A52") list = rng.Value t = UBound(list, 1) j = t Randomize For i = 1 To t k = Int(Rnd() * j + 1) lngTemp = list(j, 1) list(j, 1) = list(k, 1) list(k, 1) = lngTemp j = j - 1 Next rng.Value = list End Sub -- Regards, Tom Ogilvy wrote in message oups.com... I need VB code to Randomly generat numbers from 1 to 52. Can anybody help? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Random number Generator | New Users to Excel | |||
Random number generator | Excel Worksheet Functions | |||
Random Number generator | Excel Worksheet Functions | |||
Random Number Generator | Excel Programming | |||
Random Number Generator | Excel Programming |