Branch: Tag:

2010-03-23

2010-03-23 12:24:39 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Fixed bug in random() for sizes larger than 31 bits, but smaller than the bignum threshold.

Rev: src/builtin.cmod:1.110

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin.cmod,v 1.109 2008/04/22 18:17:55 mast Exp $ + || $Id: builtin.cmod,v 1.110 2010/03/23 12:24:39 grubba Exp $   */      #include "global.h"
902:   PIKEFUN int random(int i)   {    if(i <= 0) RETURN 0; + #ifdef AUTO_BIGNUM +  if(i >> 31) { +  unsigned INT_TYPE a = my_rand(); +  unsigned INT_TYPE b = my_rand(); +  RETURN (INT_TYPE)(((a<<32)|b) % i); +  } + #endif    RETURN my_rand() % i;   }