Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random Number comparison

I am trying to compare a randomly generated number by the previous randomly
generated number in the same cell. I would like to know if the new number is
higher or lower than the provious number. Once known i would like to add up
these occurances. ie out of 100 calculations 45 were higher and 55 were
lower. 45 and 55 should be shown in the next cells. Any suggestions would
be a great help.

Philip Morritt
University West England Bristol
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random Number comparison

Thanks for that but unfortunatly the random number equation is copied which
produces a new number when pasting, it runs the calculation as if hitting F9.

"Barb Reinhardt" wrote:

I'd copy and paste the first column of data so that when you recalculate,
you don't lose your numbers.
Create another column of random numbers.
=if(a1B1,"Less",if(a1<b1,"More",Equal))

"Philip Morritt" <Philip wrote in message
...
I am trying to compare a randomly generated number by the previous randomly
generated number in the same cell. I would like to know if the new number
is
higher or lower than the provious number. Once known i would like to add
up
these occurances. ie out of 100 calculations 45 were higher and 55 were
lower. 45 and 55 should be shown in the next cells. Any suggestions
would
be a great help.

Philip Morritt
University West England Bristol




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default Random Number comparison

Philip Morritt wrote:

Thanks for that but unfortunatly the random number equation is copied which
produces a new number when pasting, it runs the calculation as if hitting F9.


You want to use Paste Special / # values. That will preserve the numeric
values of the original set of random numbers. Why do you want to do this?

Regards,
Martin Brown

"Barb Reinhardt" wrote:


I'd copy and paste the first column of data so that when you recalculate,
you don't lose your numbers.
Create another column of random numbers.
=if(a1B1,"Less",if(a1<b1,"More",Equal))

"Philip Morritt" <Philip wrote in message
...

I am trying to compare a randomly generated number by the previous randomly
generated number in the same cell. I would like to know if the new number
is
higher or lower than the provious number. Once known i would like to add
up
these occurances. ie out of 100 calculations 45 were higher and 55 were
lower. 45 and 55 should be shown in the next cells. Any suggestions
would
be a great help.

Philip Morritt
University West England Bristol






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Random Number comparison

It's easy enough to compare and record changes made by your Random formula.
Problem is each time you update cells with change comparisons a new
Calculate event will trigger a new Random change.

You could store changes in a VBA variables or array and access when needed -

Right click sheet tab, view code and paste into the sheet module

Dim prevRnd As Double

Private Sub Worksheet_Calculate()
Dim newRnd As Double

newRnd = Range("A1").Value ' // change to address of RAND formula

If newRnd prevRnd Then
aRndCount(1) = aRndCount(1) + 1 ' more count
ElseIf newRnd < prevRnd Then
aRndCount(2) = aRndCount(2) + 1 ' less count
Else
aRndCount(3) = aRndCount(3) + 1 ' same count
End If
aRndCount(4) = aRndCount(4) + 1 ' total changes count
prevRnd = newRnd

End Sub

Insert a normal module for the following code

' top of normal module

Public aRndCount(1 To 4) As Long

Sub DumpRndCount()
' may trigger a calculation event & new Rand

' first select first cell of a row of four to dump values

ActiveCell.Resize(1, 4).Value = aRndCount

If MsgBox("Clear Rand History", vbYesNo) = vbYes Then
Erase aRndHistory
End If

End Sub

Sub RndCountMsg()
' does not trigger a calc event
Dim s As String
s = "More : " & vbTab & aRndCount(1) & vbCr
s = s & "Less : " & vbTab & aRndCount(2) & vbCr
s = s & "Same : " & vbTab & aRndCount(3) & vbCr
s = s & "Total : " & vbTab & aRndCount(4) & vbCr

MsgBox s

If MsgBox("Clear Rand History", vbYesNo) = vbYes Then
Erase aRndCount
End If
End Sub

Along similar lines could store in an array up to 64k actual rand values and
return the entire history to cells.

Regards,
Peter T

"Philip Morritt" <Philip wrote in message
...
I am trying to compare a randomly generated number by the previous

randomly
generated number in the same cell. I would like to know if the new number

is
higher or lower than the provious number. Once known i would like to add

up
these occurances. ie out of 100 calculations 45 were higher and 55 were
lower. 45 and 55 should be shown in the next cells. Any suggestions

would
be a great help.

Philip Morritt
University West England Bristol



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Random Number comparison

You could try this

ToolsOptionsCalculation and check the Iteration box to stop circular
references

Adjust your randomising formula, in a manner like this

=IF(($B$1="")+(A10),A1,INT(RAND()*100+1))

Add my formula =SUMPRODUCT(--(A1:A99<A2:A100)) in another cell

then put some value in B1

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Bob Phillips" wrote in message
...
If the range of numbers is in A1:A100, use

=SUMPRODUCT(--(A1:A99<A2:A100))

for higher


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Philip Morritt" <Philip wrote in

message
...
I am trying to compare a randomly generated number by the previous

randomly
generated number in the same cell. I would like to know if the new

number
is
higher or lower than the provious number. Once known i would like to

add
up
these occurances. ie out of 100 calculations 45 were higher and 55 were
lower. 45 and 55 should be shown in the next cells. Any suggestions

would
be a great help.

Philip Morritt
University West England Bristol





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Random Number comparison

Probably best to also use

=IF(($B$1="")+(E10),E1,SUMPRODUCT(--(A1:A99<A2:A100)))

where E1 is the cell of that formula.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Bob Phillips" wrote in message
...
You could try this

ToolsOptionsCalculation and check the Iteration box to stop circular
references

Adjust your randomising formula, in a manner like this

=IF(($B$1="")+(A10),A1,INT(RAND()*100+1))

Add my formula =SUMPRODUCT(--(A1:A99<A2:A100)) in another cell

then put some value in B1

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Bob Phillips" wrote in message
...
If the range of numbers is in A1:A100, use

=SUMPRODUCT(--(A1:A99<A2:A100))

for higher


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Philip Morritt" <Philip wrote in

message
...
I am trying to compare a randomly generated number by the previous

randomly
generated number in the same cell. I would like to know if the new

number
is
higher or lower than the provious number. Once known i would like to

add
up
these occurances. ie out of 100 calculations 45 were higher and 55

were
lower. 45 and 55 should be shown in the next cells. Any suggestions

would
be a great help.

Philip Morritt
University West England Bristol







  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random Number comparison


Philip,

I really don't know the object of your exercise-comparing which way a
number falls. In principle, random number generation algorithm ensures
that there will, -on average-, be an even chance of getting either
event. If you populate A1:A100 & B1:B100 with random numbers, and you
repeat the exercise N times, you are likely to generate a distribution
where the number of times values in Column A exceed those in Column B
will flatten out. The higher the value of N, the greater the probabilty
being 0.5 each way. Any departure from this asymptotic value is purely
attributable to random error in the sampling process.

Just an observation.


--
Myles
------------------------------------------------------------------------
Myles's Profile: http://www.excelforum.com/member.php...o&userid=28746
View this thread: http://www.excelforum.com/showthread...hreadid=501462

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
Number Value Comparison and matching PayPaul Excel Worksheet Functions 0 November 13th 07 06:31 PM
Addding a Random number to a fixed number..... Dermot Excel Discussion (Misc queries) 6 August 20th 06 12:17 PM
How can I match a random number with closest number from sequence? Matt Excel Worksheet Functions 4 August 3rd 06 01:22 AM
Generating (in a random order)each number once from a given number Neil Goldwasser Excel Worksheet Functions 2 December 2nd 05 11:27 PM
How do I find random number in list of random alpha? (Position is. jlahealth-partners Excel Discussion (Misc queries) 0 February 8th 05 05:31 PM


All times are GMT +1. The time now is 01:47 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"