Is there something wrong with the random generator in Excel?
"JasonK" wrote:
When I call the random generator, "Randomize" on
a certain line, the player wins consistently. When
I move the Randomize line down a few lines of code,
the house wins consistently.
That sounds like a coincidence or a defect in your code. To address, it
would be helpful to see the entire macro (and called procedures).
But note that Randomize should be called only one time. Arguably, it should
not hurt to call it multiple times. But its purpose is to "seed"
(initialize) the pseudorandom number generator. "Seeding" is typically done
only one time.
There are many ways to do this. If your macro is called only one time, the
simplest way is to put the Randomize statement outside any loops, typically
at the beginning of the macro. If your macro is called successively, you
could use a static variable to ensure that Randomize is called only the
first time, e.g.:
Static notFirst As Integer
If notFirst = 0 Then Randomize: notFirst = 1
Note: "first" will be initially zero each time VBA is reset. If that
bothers you, you can put the Randomize in another macro, which is executed
only one time.
----- original message -----
"JasonK" wrote in message
...
TIA --
I'm running 2003.
I've created a spreadsheet that plays craps. I've written a lengthy
macro in old basic language that runs fine. It rolls 2 dice, sums the
total, places wagers in columns and totals winners and losers and
keeps a running total of a bankroll. It's designed to play a specific
way that I saw some one play who happened to be winning a lot of
money.
When I call the random generator, "Randomize" on a certain line, the
player wins consistently. When I move the Randomize line down a few
lines of code, the house wins consistently.
Is there something inherently wrong with the Random generator in
Excel? Is there a better way to call a Random number that
"Randomize"? I used to use "Randomize Timer" with the old basic
language. That doesn't seem to make a difference here.
Thanks for your help,
JasonK
|