rand function is repeating

R

Romanian37

All,

I've created a little test to keep my arithmetic skills up, which ask
me to multiply two numbers together (up to a certain limit), it wil
then record the time that I took to answer and record my answer in th
worksheet. I can then hopefully see myself get quicker over time, wit
more complex combinations.

Whenever I open up excel, the numbers I am asked are always the sam
(22*17, 12 *24, etc). Appart from running the macro a few times, i
there anyway I can make the rand function actually random, and no
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
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 Su
 
S

sebastienm

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
 

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