Posted to microsoft.public.excel.programming
|
|
rand function is repeating
Hi Will,
Add the Randomize statement at the begining of the sub:
Sub RandomNumber()
Dim MyValue1 As Integer
'...
Randomize
On Error GoTo error1
'...
End Sub
Regards,
Sebastien
"Romanian37" wrote:
All,
I've created a little test to keep my arithmetic skills up, which asks
me to multiply two numbers together (up to a certain limit), it will
then record the time that I took to answer and record my answer in the
worksheet. I can then hopefully see myself get quicker over time, with
more complex combinations.
Whenever I open up excel, the numbers I am asked are always the same
(22*17, 12 *24, etc). Appart from running the macro a few times, is
there anyway I can make the rand function actually random, and not
dependent on how many times I've asked it to be random?
code below
Cheers
Will
Sub RandomNumber()
Dim MyValue1 As Integer
Dim MyValue2 As Integer
Dim InputboxEntry As Integer
Dim StartTime As Single
Dim EndTime As Single
On Error GoTo error1
Range(Cells(2, 1), Cells(50, 6)).ClearContents
For i = 1 To 10
MyValue1 = Int((22 * Rnd) + 1) + 8 ' Generate random value between 1
and 100
MyValue2 = Int((22 * Rnd) + 1) + 8
StartTime = Time
InputboxEntry = InputBox(MyValue1 & " * " & MyValue2)
EndTime = Time
Cells(i + 1, 1).Value = MyValue1
Cells(i + 1, 2).Value = MyValue2
Cells(i + 1, 3).Value = MyValue1 * MyValue2
Cells(i + 1, 4).Value = InputboxEntry
Cells(i + 1, 5).Value = StartTime
Cells(i + 1, 6).Value = EndTime
error1:
Next i
End Sub
--
Romanian37
------------------------------------------------------------------------
Romanian37's Profile: http://www.excelforum.com/member.php...fo&userid=9759
View this thread: http://www.excelforum.com/showthread...hreadid=261941
|