source: zzuf/trunk/src/random.c @ 1523

Last change on this file since 1523 was 1523, checked in by Sam Hocevar, 14 years ago
  • Improved zfd_register() and zfd_* function performances.
  • Changed function names here and there.
  • Property svn:keywords set to Id
File size: 964 bytes
Line 
1/*
2 *  zzuf - general purpose fuzzer
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: random.c 1523 2006-12-28 20:22:32Z sam $
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
30void _zz_srand(uint32_t seed)
31{
32    srand(seed ^ 0x12345678);
33}
34
35uint32_t _zz_rand(uint32_t max)
36{
37    if(max <= RAND_MAX)
38        return rand() % max;
39
40    /* Could be better, but do we care? */
41    return (uint32_t)((max * 1.0) * (rand() / (RAND_MAX + 1.0)));
42}
43
Note: See TracBrowser for help on using the repository browser.