Random Numbers

M

Michael

Hi All
I have a spreadsheet for doing a raffle draw at our local
club.
I am using the code below to "Spin" the numbers.
However, as we only do about 12-14 prizes, I have noticed
a tendency for the numbers to be skewed in favour of the
lower half of the draw.
In 14 numbers, usually 10 or more of them are in the lower
half.
Is there any way to "discourage this to make the numbers a
little more balanced.
Any comments would be appreciated

Option Explicit
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)
Sub Spin()
Dim X As Integer
Dim CellA As Range, CellB As Range
Set CellA = Worksheets("Draw").Range("M7")
Set CellB = Worksheets("Draw").Range("M5")
For X = 1 To 75
Range("I8") = Int((CellA + 1 - CellB) * Rnd + CellB)
Sleep 20
Next X
End Sub

Regards
Michael
 
S

Stan Scott

According to HELP:

a.. To generate a random real number between a and b, use:
RAND()*(b-a)+a

I don't think this is what you're doing right now.

Stan Scott

New York City
 
M

Michael

Firstly, thanks for the input.
I have taken onboard your comment and input the line into
the Macro. However, I am getting a compile error.
Can you enilghten me a little more as to the syntax and
location of the Rand Line
Regards
Michael
 
S

Stan Scott

Michael,

Sorry, it's "RAND" when you use it in a worksheet formula, but "RND" when
you use it in VBA. Sorry for the confusion.

Stan
 
K

Kostis Vezerides

Michael,
When I saw your macro I didn's see anything wrong. Indeed
it should produce numbers from CellB to CellA with uniform
probability.

I tried it and indeed it produced uniform probability.
Seems to me it is only an impression. Try a variant
For X = 1 To 75
Cells(X, 3) = Int((CellA + 1 - CellB) * Rnd + CellB)

Next X
to have it print the values produced and produce a
histogram. You will likely see that the probability is
uniform.

Kostis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top