Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
RAND FUNCTION NADTARVIN Excel Worksheet Functions 1 September 29th 06 05:56 AM
HELP with the RAND() Function......AGAIN!!!!! denise1082 via OfficeKB.com Excel Worksheet Functions 9 July 31st 06 12:53 PM
HELP with the RAND() Function!!!!!! denise1082 Excel Worksheet Functions 15 July 31st 06 07:54 AM
RAND FUNCTION theo499 New Users to Excel 2 April 11th 06 05:08 AM
Rand() function SMANDA Excel Discussion (Misc queries) 1 February 8th 05 12:59 AM


All times are GMT +1. The time now is 05:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"