| Revision 4112,
1.0 KB
checked in by sam, 3 years ago
(diff) |
|
Reorganise source code to better separate zzuf and libzzuf. Note: the Win32
build is now broken.
|
-
Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 | /* |
|---|
| 2 | * zzuf - general purpose fuzzer |
|---|
| 3 | * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
|---|
| 4 | * All Rights Reserved |
|---|
| 5 | * |
|---|
| 6 | * $Id$ |
|---|
| 7 | * |
|---|
| 8 | * This program is free software. It comes without any warranty, to |
|---|
| 9 | * the extent permitted by applicable law. You can redistribute it |
|---|
| 10 | * and/or modify it under the terms of the Do What The Fuck You Want |
|---|
| 11 | * To Public License, Version 2, as published by Sam Hocevar. See |
|---|
| 12 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
|---|
| 13 | */ |
|---|
| 14 | |
|---|
| 15 | /* |
|---|
| 16 | * random.c: pseudorandom number generator |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | #include "config.h" |
|---|
| 20 | |
|---|
| 21 | #if defined HAVE_STDINT_H |
|---|
| 22 | # include <stdint.h> |
|---|
| 23 | #elif defined HAVE_INTTYPES_H |
|---|
| 24 | # include <inttypes.h> |
|---|
| 25 | #endif |
|---|
| 26 | #include <stdlib.h> |
|---|
| 27 | |
|---|
| 28 | #include "random.h" |
|---|
| 29 | |
|---|
| 30 | static unsigned long ctx = 1; |
|---|
| 31 | |
|---|
| 32 | void _zz_srand(uint32_t seed) |
|---|
| 33 | { |
|---|
| 34 | ctx = (seed ^ 0x12345678); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | uint32_t _zz_rand(uint32_t max) |
|---|
| 38 | { |
|---|
| 39 | /* Could be better, but do we care? */ |
|---|
| 40 | long hi, lo, x; |
|---|
| 41 | |
|---|
| 42 | hi = ctx / 12773L; |
|---|
| 43 | lo = ctx % 12773L; |
|---|
| 44 | x = 16807L * lo - 2836L * hi; |
|---|
| 45 | if(x <= 0) |
|---|
| 46 | x += 0x7fffffffL; |
|---|
| 47 | return (ctx = x) % (unsigned long)max; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.