[Patches] A bug fix to betavariate() in random.py

Janne Sinkkonen janne@nnets.fi
26 May 2000 16:19:31 +0300


The betavariate() in random.py has nothing to do with beta-distributed
random numbers. Here's something that works:

*** random.py.orig	Fri May 26 16:11:23 2000
--- random.py	Fri May 26 16:12:49 2000
***************
*** 270,280 ****
  # -------------------- beta --------------------
  
  def betavariate(alpha, beta):
  
! 	# Discrete Event Simulation in C, pp 87-88.
! 
! 	y = expovariate(alpha)
! 	z = expovariate(1.0/beta)
  	return z/(y+z)
  
  # -------------------- Pareto --------------------
--- 270,281 ----
  # -------------------- beta --------------------
  
  def betavariate(alpha, beta):
+ 	# Devroye, L. (1986) Non-Uniform Random Variate Generation,
+ 	# theorem 4.1A (p. 430)
+ 	# Bug fix courtesy Janne Sinkkonen <janne@iki.fi>
  
! 	y = gammavariate(alpha,1)
! 	z = gammavariate(beta,1)
  	return z/(y+z)
  
  # -------------------- Pareto --------------------


I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under copyright,
patent or other rights or interests ("claims").  To the extent that I
have any such claims, I hereby grant to CNRI a nonexclusive,
irrevocable, royalty-free, worldwide license to reproduce, distribute,
perform and/or display publicly, prepare derivative versions, and
otherwise use this contribution as part of the Python software and its
related documentation, or any derivative versions thereof, at no cost
to CNRI or its licensed users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether or
not to incorporate this contribution in the Python software and its
related documentation.  I further grant CNRI permission to use my name
and other identifying information provided to CNRI by me for use in
connection with the Python software and its related documentation.

-- 
Janne Sinkkonen
<janne@nnets.fi>