Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default VBA randomize vs. srand

Hi,

I'm trying to make a VBA version of a shuffling algorithm I've seen,
which is written (I think) in C. I've got the shape of it, I think, but
I think there is a problem due to the Randomize() seed function in vba
and the srand() function in C. Do they work the same way? How can I
replicate the behaviour of srand in vba?

Cheers,

Chris

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default VBA randomize vs. srand

Chris,
The VBA Help, explains the VBA psuedo random numbers.
From what I can tell about srand, this will replicate it, with the statement
"Rnd (-100)" ensuring that the same seed value gives the same number
sequence.
Comment out that and the same seed gives a different sequence, unlike srand.

Private Sub CommandButton1_Click()
Dim Runs As Long
Dim CellsToFill As Long

Const RunsMax As Long = 10
Const CellsMax As Long = 1000

Cells.ClearContents

For Runs = 1 To RunsMax
Rnd (-100)
Randomize (10)

For CellsToFill = 1 To CellsMax
Cells(CellsToFill, Runs).Value = Rnd()
Next
Next
End Sub

NickHK

wrote in message
ups.com...
Hi,

I'm trying to make a VBA version of a shuffling algorithm I've seen,
which is written (I think) in C. I've got the shape of it, I think, but
I think there is a problem due to the Randomize() seed function in vba
and the srand() function in C. Do they work the same way? How can I
replicate the behaviour of srand in vba?

Cheers,

Chris



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
Randomize from a list PEGWINN Excel Discussion (Misc queries) 12 August 4th 09 11:59 AM
randomize data rmg2828 Excel Discussion (Misc queries) 1 July 17th 06 05:01 PM
How can I randomize a set of data? Hannie1004 Excel Worksheet Functions 1 February 14th 06 10:06 PM
How to Randomize Files? Jan Nademlejnsky Excel Programming 0 October 21st 04 02:22 AM
randomize dallas Excel Programming 11 May 30th 04 08:27 PM


All times are GMT +1. The time now is 04:36 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"