Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
RandomProblems
 
Posts: n/a
Default How do I add the sum of a series numbers generated by Rnd gen?

I need to create the sum of 2,500,000 iterations generated by the Rnd
generator function. I cannot create y=X(1)+X(2)+......X(n) where y is the
sum and x (the first iteration, x(2) the second and so on.
  #2   Report Post  
Rowan
 
Posts: n/a
Default

I am assuming you are wanting to do this in a macro as you have used Rnd and
not the worksheet function Rand. You could do it like this

Sub RandomSum()
Dim i As Long
Dim y As Double
For i = 1 To 2500000
y = y + Rnd()
Next i
MsgBox y
End Sub

but it would be a lot more efficient and probably not materially different
to do this:

Sub RandomSum()
Dim i As Integer
Dim y As Double
For i = 1 To 25
y = y + Rnd() * 100000
Next i
MsgBox y
End Sub

Hope this helps
Rowan

"RandomProblems" wrote:

I need to create the sum of 2,500,000 iterations generated by the Rnd
generator function. I cannot create y=X(1)+X(2)+......X(n) where y is the
sum and x (the first iteration, x(2) the second and so on.

  #3   Report Post  
arno
 
Posts: n/a
Default

Hi,

you need a macor for this. However, you'll always get the same result.
Run my code, in column A you'll see the sum you are looking for (250,
2500... 2.5Mio iterations), in column B you'll see the average, which
will always be the same.

Sub test()
Randomize
x = 0
v = 25
For j = 1 To 5
v = v * 10
For i = 1 To v
x = x + Rnd()
Next
Cells(j, 1).Value = x
Cells(j, 2).Value = x / v
Next j
End Sub

the important part for you is:
for i = 1 to 2500000
x = x+Rnd()
next

arno

"RandomProblems" schrieb im
Newsbeitrag ...
I need to create the sum of 2,500,000 iterations generated by the Rnd
generator function. I cannot create y=X(1)+X(2)+......X(n) where y

is the
sum and x (the first iteration, x(2) the second and so on.


  #4   Report Post  
RandomProblems
 
Posts: n/a
Default

Thanks for the reply. It is exactly what I needed.

"Rowan" wrote:

I am assuming you are wanting to do this in a macro as you have used Rnd and
not the worksheet function Rand. You could do it like this

Sub RandomSum()
Dim i As Long
Dim y As Double
For i = 1 To 2500000
y = y + Rnd()
Next i
MsgBox y
End Sub

but it would be a lot more efficient and probably not materially different
to do this:

Sub RandomSum()
Dim i As Integer
Dim y As Double
For i = 1 To 25
y = y + Rnd() * 100000
Next i
MsgBox y
End Sub

Hope this helps
Rowan

"RandomProblems" wrote:

I need to create the sum of 2,500,000 iterations generated by the Rnd
generator function. I cannot create y=X(1)+X(2)+......X(n) where y is the
sum and x (the first iteration, x(2) the second and so on.

  #5   Report Post  
RandomProblems
 
Posts: n/a
Default

Thank you for the insitefull response. I guess I am going to do some reading.

"arno" wrote:

Hi,

you need a macor for this. However, you'll always get the same result.
Run my code, in column A you'll see the sum you are looking for (250,
2500... 2.5Mio iterations), in column B you'll see the average, which
will always be the same.

Sub test()
Randomize
x = 0
v = 25
For j = 1 To 5
v = v * 10
For i = 1 To v
x = x + Rnd()
Next
Cells(j, 1).Value = x
Cells(j, 2).Value = x / v
Next j
End Sub

the important part for you is:
for i = 1 to 2500000
x = x+Rnd()
next

arno

"RandomProblems" schrieb im
Newsbeitrag ...
I need to create the sum of 2,500,000 iterations generated by the Rnd
generator function. I cannot create y=X(1)+X(2)+......X(n) where y

is the
sum and x (the first iteration, x(2) the second and so on.



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
How to change Series order in a Combination Chart? vrk1 Charts and Charting in Excel 3 April 1st 05 07:21 AM
How to convert a series of numbers Robert Judge Excel Worksheet Functions 4 March 31st 05 03:52 PM
series graph -- one series being added to another series rich zielinski via OfficeKB.com Charts and Charting in Excel 3 March 30th 05 06:23 PM
Converting Numbers to Text properly Shirley Munro Excel Discussion (Misc queries) 1 February 16th 05 03:01 PM
Randomly Sort a Series of Numbers Shoelaces Excel Discussion (Misc queries) 3 January 8th 05 07:25 PM


All times are GMT +1. The time now is 06:03 AM.

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"