Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Randomize from a list | Excel Discussion (Misc queries) | |||
randomize data | Excel Discussion (Misc queries) | |||
How can I randomize a set of data? | Excel Worksheet Functions | |||
How to Randomize Files? | Excel Programming | |||
randomize | Excel Programming |