View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Romanian37[_10_] Romanian37[_10_] is offline
external usenet poster
 
Posts: 1
Default rand function is repeating


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

--
Romanian3
-----------------------------------------------------------------------
Romanian37's Profile: http://www.excelforum.com/member.php...nfo&userid=975
View this thread: http://www.excelforum.com/showthread.php?threadid=26194