Branch: Tag:

2010-03-23

2010-03-23 12:24:23 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.161

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.160 2008/04/23 07:37:03 mast Exp $ + || $Id: builtin.cmod,v 1.161 2010/03/23 12:24:23 grubba Exp $   */      #include "global.h"
1096:   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;   }