1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/liboilrandom.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,129 @@
1.4 +/*
1.5 + * LIBOIL - Library of Optimized Inner Loops
1.6 + * Copyright (c) 2003,2004,2005 David A. Schleef <ds@schleef.org>
1.7 + * All rights reserved.
1.8 + *
1.9 + * Redistribution and use in source and binary forms, with or without
1.10 + * modification, are permitted provided that the following conditions
1.11 + * are met:
1.12 + * 1. Redistributions of source code must retain the above copyright
1.13 + * notice, this list of conditions and the following disclaimer.
1.14 + * 2. Redistributions in binary form must reproduce the above copyright
1.15 + * notice, this list of conditions and the following disclaimer in the
1.16 + * documentation and/or other materials provided with the distribution.
1.17 + *
1.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1.20 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
1.22 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1.23 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.25 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1.26 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
1.27 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1.28 + * POSSIBILITY OF SUCH DAMAGE.
1.29 + */
1.30 +
1.31 +#ifndef _LIBOIL_RANDOM_H_
1.32 +#define _LIBOIL_RANDOM_H_
1.33 +
1.34 +#include <liboil/liboilutils.h>
1.35 +#include <liboil/liboiltypes.h>
1.36 +#include <stdlib.h>
1.37 +
1.38 +OIL_BEGIN_DECLS
1.39 +
1.40 +#ifdef OIL_ENABLE_UNSTABLE_API
1.41 +
1.42 +IMPORT_C void oil_random_s32(oil_type_s32 *dest, int n);
1.43 +IMPORT_C void oil_random_s64 (oil_type_s64 *dest, int n);
1.44 +IMPORT_C void oil_random_s16 (oil_type_s16 *dest, int n);
1.45 +IMPORT_C void oil_random_s8 (oil_type_s8 *dest, int n);
1.46 +IMPORT_C void oil_random_u32 (oil_type_u32 *dest, int n);
1.47 +IMPORT_C void oil_random_u64 (oil_type_u64 *dest, int n);
1.48 +IMPORT_C void oil_random_u16 (oil_type_u16 *dest, int n);
1.49 +IMPORT_C void oil_random_u8 (oil_type_u8 *dest, int n);
1.50 +IMPORT_C void oil_random_f64 (oil_type_f64 *dest, int n);
1.51 +IMPORT_C void oil_random_f32 (oil_type_f32 *dest, int n);
1.52 +IMPORT_C void oil_random_argb (oil_type_u32 *dest, int n);
1.53 +IMPORT_C void oil_random_alpha (oil_type_u8 *dest, int n);
1.54 +
1.55 +/**
1.56 + * oil_rand_s32:
1.57 + *
1.58 + * Evaluates to a random integer in the range [-(1<<31), (1<<31)-1].
1.59 + */
1.60 +#define oil_rand_s32() ((rand()&0xffff)<<16 | (rand()&0xffff))
1.61 +/**
1.62 + * oil_rand_s64:
1.63 + *
1.64 + * Evaluates to a random integer in the range [-(1<<63), (1<<63)-1].
1.65 + */
1.66 +#define oil_rand_s64() ((int64_t)(oil_rand_s32())<<32 | oil_rand_s32())
1.67 +
1.68 +/**
1.69 + * oil_rand_s16:
1.70 + *
1.71 + * Evaluates to a random integer in the range [-(1<<15), (1<<15)-1].
1.72 + */
1.73 +#define oil_rand_s16() ((int16_t)(rand()&0xffff))
1.74 +
1.75 +/**
1.76 + * oil_rand_s8:
1.77 + *
1.78 + * Evaluates to a random integer in the range [-(1<<7), (1<<7)-1].
1.79 + */
1.80 +#define oil_rand_s8() ((int8_t)(rand()&0xffff))
1.81 +
1.82 +/**
1.83 + * oil_rand_u32:
1.84 + *
1.85 + * Evaluates to a random integer in the range [0, (1<<32)-1].
1.86 + */
1.87 +#define oil_rand_u32() ((uint32_t)((rand()&0xffff)<<16 | (rand()&0xffff)))
1.88 +
1.89 +/**
1.90 + * oil_rand_u64:
1.91 + *
1.92 + * Evaluates to a random integer in the range [0, (1<<64)-1].
1.93 + */
1.94 +#define oil_rand_u64() ((uint64_t)(oil_rand_u32())<<32 | oil_rand_u32())
1.95 +
1.96 +/**
1.97 + * oil_rand_u16:
1.98 + *
1.99 + * Evaluates to a random integer in the range [0, (1<<16)-1].
1.100 + */
1.101 +#define oil_rand_u16() ((uint16_t)(rand()&0xffff))
1.102 +
1.103 +/**
1.104 + * oil_rand_u8:
1.105 + *
1.106 + * Evaluates to a random integer in the range [0, (1<<8)-1].
1.107 + */
1.108 +#define oil_rand_u8() ((uint8_t)(rand()&0xffff))
1.109 +
1.110 +
1.111 +/**
1.112 + * oil_rand_f64:
1.113 + *
1.114 + * Evaluates to a random double-precision floating point number
1.115 + * in the range [0, 1.0).
1.116 + */
1.117 +#define oil_rand_f64() (((rand()/(RAND_MAX+1.0))+rand())/(RAND_MAX+1.0))
1.118 +
1.119 +/**
1.120 + * oil_rand_f32:
1.121 + *
1.122 + * Evaluates to a random single-precision floating point number
1.123 + * in the range [0, 1.0).
1.124 + */
1.125 +#define oil_rand_f32() (rand()/(RAND_MAX+1.0))
1.126 +
1.127 +#endif
1.128 +
1.129 +OIL_END_DECLS
1.130 +
1.131 +#endif
1.132 +