On Fri, 2005-05-20 at 08:22 -0400, Andrew Douglas Pitonyak wrote: > Int() rounds towards negative infinity. > Rnd() returns a number from 0 to 1 inclusive. At least this is how I > documented it in my book, and how I understand the online help. I have > not checked the source code to see what it does. >
Could this be caused by OOo's tendency to display numbers according to the number of decimal places specified? e.g. 0.9999999 would display as 1.00 where two decimal places is spec'd. > Johnny Andersson wrote: > > > I found that the Rnd function returns values (0.00000... to > > 1.00000...), not (0.00000... to 0.99999...), which would be better in > > most cases. > > > > Example: > > Dim MyInteger As Integer > > Dim MyArray(1 To 6) As Integer > > > > Randomize > > MyInteger=Int(6*Rnd)+1 'Supposed to return numbers 1 to 6, byt may now > > and then return 7. Happened to me many times. > > MyArray(MyInteger)=MyArray(MyInteger)+1 'Causes an error message if > > MyInteger>6 which may happen in this case. > > > > In this example Rnd returns 1. > > > > Sub RndTest > > Randomize 30091 > > Print Rnd > > End Sub > > > > > > This example took about 2 minutes to run on my PC (450 MHz P2, a few > > other applications were running at the same time): > > > > Sub RndTest0 > > Dim i As Long > > Dim Count1 As Integer, Count2 As Integer > > Dim Value As Double > > Dim ExecTime As Long > > > > ExecTime=Timer > > Randomize > > For i=1 To 1000000 > > Value=Rnd > > If Value>0.99999 Then > > Count1=Count1+1 > > If Value=1 Then > > Count2=Count2+1 > > Endif > > EndIf > > Next i > > ExecTime=Timer-ExecTime > > Print "Rnd>0.99999 occured "+Count1+" times, Rnd=1 occured "+Count2+" > > times. This was calculated in "+ExecTime+" s." > > End Sub > > > > It seems like every time Rnd>0.99999 then Rnd=1, so even though Rnd > > produces 15 decimals it seems like only 5 (or less) are relevant. When > > I tried Rnd=1 at 20 to 34 occasions (different result different times > > of course) which indicates that Rnd=1 about once every 29000 to 50000 > > times. > > > > Anyway, is Rnd=1 supposed to ever happen or is this a bug? > -- PLEASE KEEP MESSAGES ON THE LIST. OpenOffice.org Documentation Co-Lead http://documentation.openoffice.org/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
