SDL Library
Embed:
(wiki syntax)
Show/hide line numbers
SDL_test_random.h
Go to the documentation of this file.
00001 /* 00002 Simple DirectMedia Layer 00003 Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any damages 00007 arising from the use of this software. 00008 00009 Permission is granted to anyone to use this software for any purpose, 00010 including commercial applications, and to alter it and redistribute it 00011 freely, subject to the following restrictions: 00012 00013 1. The origin of this software must not be misrepresented; you must not 00014 claim that you wrote the original software. If you use this software 00015 in a product, an acknowledgment in the product documentation would be 00016 appreciated but is not required. 00017 2. Altered source versions must be plainly marked as such, and must not be 00018 misrepresented as being the original software. 00019 3. This notice may not be removed or altered from any source distribution. 00020 */ 00021 00022 /** 00023 * \file SDL_test_random.h 00024 * 00025 * Include file for SDL test framework. 00026 * 00027 * This code is a part of the SDL2_test library, not the main SDL library. 00028 */ 00029 00030 /* 00031 00032 A "32-bit Multiply with carry random number generator. Very fast. 00033 Includes a list of recommended multipliers. 00034 00035 multiply-with-carry generator: x(n) = a*x(n-1) + carry mod 2^32. 00036 period: (a*2^31)-1 00037 00038 */ 00039 00040 #ifndef _SDL_test_random_h 00041 #define _SDL_test_random_h 00042 00043 #include "begin_code.h" 00044 /* Set up for C function definitions, even when using C++ */ 00045 #ifdef __cplusplus 00046 extern "C" { 00047 #endif 00048 00049 /* --- Definitions */ 00050 00051 /* 00052 * Macros that return a random number in a specific format. 00053 */ 00054 #define SDLTest_RandomInt(c) ((int)SDLTest_Random(c)) 00055 00056 /* 00057 * Context structure for the random number generator state. 00058 */ 00059 typedef struct { 00060 unsigned int a; 00061 unsigned int x; 00062 unsigned int c; 00063 unsigned int ah; 00064 unsigned int al; 00065 } SDLTest_RandomContext; 00066 00067 00068 /* --- Function prototypes */ 00069 00070 /** 00071 * \brief Initialize random number generator with two integers. 00072 * 00073 * Note: The random sequence of numbers returned by ...Random() is the 00074 * same for the same two integers and has a period of 2^31. 00075 * 00076 * \param rndContext pointer to context structure 00077 * \param xi integer that defines the random sequence 00078 * \param ci integer that defines the random sequence 00079 * 00080 */ 00081 void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi, 00082 unsigned int ci); 00083 00084 /** 00085 * \brief Initialize random number generator based on current system time. 00086 * 00087 * \param rndContext pointer to context structure 00088 * 00089 */ 00090 void SDLTest_RandomInitTime(SDLTest_RandomContext *rndContext); 00091 00092 00093 /** 00094 * \brief Initialize random number generator based on current system time. 00095 * 00096 * Note: ...RandomInit() or ...RandomInitTime() must have been called 00097 * before using this function. 00098 * 00099 * \param rndContext pointer to context structure 00100 * 00101 * \returns A random number (32bit unsigned integer) 00102 * 00103 */ 00104 unsigned int SDLTest_Random(SDLTest_RandomContext *rndContext); 00105 00106 00107 /* Ends C function definitions when using C++ */ 00108 #ifdef __cplusplus 00109 } 00110 #endif 00111 #include "close_code.h" 00112 00113 #endif /* _SDL_test_random_h */ 00114 00115 /* vi: set ts=4 sw=4 expandtab: */
Generated on Tue Jul 12 2022 15:10:20 by 1.7.2