/usr/include/vl/random.h is in libvlfeat-dev 0.9.20+dfsg0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | /** @file random.h
** @brief Random number generator (@ref random)
** @author Andrea Vedaldi
** @see @ref random
**/
/*
Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
All rights reserved.
This file is part of the VLFeat library and is made available under
the terms of the BSD license (see the COPYING file).
*/
#ifndef VL_RANDOM_H
#define VL_RANDOM_H
#include "host.h"
/** @brief Random numbber generator state */
typedef struct _VlRand {
vl_uint32 mt [624] ;
vl_uint32 mti ;
} VlRand ;
/** @name Setting and reading the state
**
** @{ */
VL_EXPORT void vl_rand_init (VlRand * self) ;
VL_EXPORT void vl_rand_seed (VlRand * self, vl_uint32 s) ;
VL_EXPORT void vl_rand_seed_by_array (VlRand * self,
vl_uint32 const key [],
vl_size keySize) ;
/** @} */
/** @name Generate random numbers
**
** @{ */
VL_INLINE vl_uint64 vl_rand_uint64 (VlRand * self) ;
VL_INLINE vl_int64 vl_rand_int63 (VlRand * self) ;
VL_EXPORT vl_uint32 vl_rand_uint32 (VlRand * self) ;
VL_INLINE vl_int32 vl_rand_int31 (VlRand * self) ;
VL_INLINE double vl_rand_real1 (VlRand * self) ;
VL_INLINE double vl_rand_real2 (VlRand * self) ;
VL_INLINE double vl_rand_real3 (VlRand * self) ;
VL_INLINE double vl_rand_res53 (VlRand * self) ;
VL_INLINE vl_uindex vl_rand_uindex (VlRand * self, vl_uindex range) ;
/** @} */
VL_EXPORT void vl_rand_permute_indexes (VlRand * self, vl_index* array, vl_size size) ;
/* ---------------------------------------------------------------- */
/** @brief Generate a random index in a given range
** @param self random number generator.
** @param range range.
** @return an index sampled uniformly at random in the interval [0, @c range - 1]
**
** @remark Currently, this function uses a simple algorithm that
** may yield slightly biased samples if @c range is not a power of
** two.
**/
VL_INLINE vl_uindex
vl_rand_uindex (VlRand * self, vl_uindex range)
{
if (range <= 0xffffffff) {
/* 32-bit version */
return (vl_rand_uint32 (self) % (vl_uint32)range) ;
} else {
/* 64-bit version */
return (vl_rand_uint64 (self) % range) ;
}
}
/** @brief Generate a random UINT64
** @param self random number generator.
** @return a random number in [0, 0xffffffffffffffff].
**/
VL_INLINE vl_uint64
vl_rand_uint64 (VlRand * self)
{
vl_uint64 a = vl_rand_uint32 (self) ;
vl_uint64 b = vl_rand_uint32 (self) ;
return (a << 32) | b ;
}
/** @brief Generate a random INT63
** @param self random number generator.
** @return a random number in [0, 0x7fffffffffffffff].
**/
VL_INLINE vl_int64
vl_rand_int63 (VlRand * self)
{
return (vl_int64)(vl_rand_uint64 (self) >> 1) ;
}
/** @brief Generate a random INT31
** @param self random number generator.
** @return a random number in [0, 0x7fffffff].
**/
VL_INLINE vl_int32
vl_rand_int31 (VlRand * self)
{
return (vl_int32)(vl_rand_uint32 (self) >> 1) ;
}
/** @brief Generate a random number in [0,1]
** @param self random number generator.
** @return a random number.
**/
VL_INLINE double
vl_rand_real1 (VlRand * self)
{
return vl_rand_uint32(self)*(1.0/4294967295.0);
/* divided by 2^32-1 */
}
/** @brief Generate a random number in [0,1)
** @param self random number generator.
** @return a random number.
**/
VL_INLINE double
vl_rand_real2 (VlRand * self)
{
return vl_rand_uint32(self)*(1.0/4294967296.0);
/* divided by 2^32 */
}
/** @brief Generate a random number in (0,1)
** @param self random number generator.
** @return a random number.
**/
VL_INLINE double
vl_rand_real3 (VlRand * self)
{
return (((double)vl_rand_uint32(self)) + 0.5)*(1.0/4294967296.0);
/* divided by 2^32 */
}
/** @brief Generate a random number in [0,1) with 53-bit resolution
** @param self random number generator.
** @return a random number.
**/
VL_INLINE double
vl_rand_res53 (VlRand * self)
{
vl_uint32
a = vl_rand_uint32(self) >> 5,
b = vl_rand_uint32(self) >> 6 ;
return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0) ;
}
/* VL_RANDOM_H */
#endif
|