1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1996-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
19 ***********************************************************************/
28 #define prng_description \
29 "32 bit PRNG (pseudo random number generator) hash."
30 #define prng_options "\
31 [+mpy?The 32 bit PRNG multiplier.]:[number:=0x01000193]\
32 [+add?The 32 bit PRNG addend.]:[number:=0]\
33 [+init?The PRNG initial value. 0xffffffff is used if \anumber\a is omitted.]:?[number:=0x811c9dc5]\
35 #define prng_match "prng"
36 #define prng_done long_done
37 #define prng_print long_print
38 #define prng_data long_data
41 typedef uint32_t Prngnum_t
;
54 prng_open(const Method_t
* method
, const char* name
)
57 register const char* s
;
58 register const char* t
;
59 register const char* v
;
62 if (sum
= newof(0, Prng_t
, 1, 0))
64 sum
->method
= (Method_t
*)method
;
70 for (t
= s
, v
= 0; *s
&& *s
!= '-'; s
++)
74 if (isdigit(*t
) || v
&& strneq(t
, "mpy", i
) && (t
= v
+ 1))
75 sum
->mpy
= strtoul(t
, NiL
, 0);
76 else if (strneq(t
, "add", i
))
77 sum
->add
= v
? strtoul(v
+ 1, NiL
, 0) : ~sum
->add
;
78 else if (strneq(t
, "init", i
))
79 sum
->init
= v
? strtoul(v
+ 1, NiL
, 0) : ~sum
->init
;
95 Prng_t
* sum
= (Prng_t
*)p
;
102 prng_block(Sum_t
* p
, const void* s
, size_t n
)
104 Prng_t
* sum
= (Prng_t
*)p
;
105 register Prngnum_t c
= sum
->sum
;
106 register unsigned char* b
= (unsigned char*)s
;
107 register unsigned char* e
= b
+ n
;
110 c
= c
* sum
->mpy
+ sum
->add
+ *b
++;