Re: TIB: weighted dice


[Prev][Next][Index][Thread]

Re: TIB: weighted dice




Jody wrote:
> 
> Um...
> int(rand*sides-2)+int(rand*2+1)+1->die1
> isn't the same as
> int(rand*sides)+int(rand*2)->die1
> 
> It is important to leave those constants inside the parentheses
> because they are being done to the random DECIMAL numbers that are
> created. Once you take them outside the parenthesese you have changed
> the number because it will do the int command FIRST and then subtract
> 2. I think. If I'm wrong (and I very well could be) PLEASE correct me!

You are wrong.

Example:
sides=6, rand turns out to be 0.23, result is:
int(0.23*6-2)+int(0.23*2+1)+1
= int(-.62)+int(1.46)+1\
= -1 + 2 = 1

My equation:
int(0.23*6)+int(0.23*2)
= int(1.38)+int(0.46)
= 1 + 0 = 1

The point you are missing is:
int(x+y) = int(x) + y if and only if y is an integer.
-2 and 1 are certainly integers :-)

Proof:
int(x.abcd...+y.0000...) = int([x+y].[abcd...+0000...])
*round down* = [x+y].00000.... = x.00000.... + y.00000.... = x+y
keep that in mente.
int(x.abcd....)+y = int([x].[abcd....]) + y
*round down* = x.0000.... + y = x+y
Well whatta you know? :-)
QED.

HTH.

-- 
          Rene Kragh Pedersen
------------------------------------------------------------------
man: Why did you get a divorce?
man:: Too many arguments.


References: