source: zzuf/trunk/src/common/random.c @ 4253

Last change on this file since 4253 was 4253, checked in by sam, 5 years ago

Fix copyright information and remove Id tag everywhere.

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