Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random Number Generator

I need VB code to Randomly generat numbers from 1 to 52. Can anybody
help?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Random Number Generator

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Random Number Generator

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random number Generator RayT New Users to Excel 14 January 15th 08 11:16 PM
Random number generator deelee Excel Worksheet Functions 3 October 12th 06 07:46 PM
Random Number generator Neil M Excel Worksheet Functions 2 February 1st 06 06:00 PM
Random Number Generator dok112[_75_] Excel Programming 7 November 18th 05 06:06 AM
Random Number Generator STEVEB Excel Programming 1 July 22nd 05 09:42 PM


All times are GMT +1. The time now is 04:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"