Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
RAND FUNCTION | Excel Worksheet Functions | |||
HELP with the RAND() Function......AGAIN!!!!! | Excel Worksheet Functions | |||
HELP with the RAND() Function!!!!!! | Excel Worksheet Functions | |||
RAND FUNCTION | New Users to Excel | |||
Rand() function | Excel Discussion (Misc queries) |