x11gfx.hidd: support 32 bit modes
[AROS.git] / compiler / alib / rangerand.c
blob2481096097a270dc1448034e79acd395e0234a0e
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <exec/types.h>
11 ULONG RangeSeed;
13 /*****************************************************************************
15 NAME */
16 #include <proto/alib.h>
18 ULONG RangeRand (
20 /* SYNOPSIS */
21 ULONG maxValue)
23 /* FUNCTION
25 INPUTS
27 RESULT
29 NOTES
31 EXAMPLE
33 BUGS
35 SEE ALSO
37 INTERNALS
39 HISTORY
40 06.12.96 digulla Created after original from libnix
42 ******************************************************************************/
44 ULONG a = RangeSeed;
45 UWORD i = maxValue - 1;
49 ULONG b = a;
51 a <<= 1;
53 if ((LONG)b <= 0)
54 a ^= 0x1d872b41;
56 } while ((i >>= 1));
58 RangeSeed = a;
60 if ((UWORD)maxValue)
61 return (UWORD)((UWORD)a * (UWORD)maxValue >> 16);
63 return (UWORD)a;
64 } /* RangeRand */