SDL Library
SDL_test_random.h@0:7fb6877b5d7c, 2016-09-22 (annotated)
- Committer:
- miruga27
- Date:
- Thu Sep 22 00:03:09 2016 +0000
- Revision:
- 0:7fb6877b5d7c
SDL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
miruga27 | 0:7fb6877b5d7c | 1 | /* |
miruga27 | 0:7fb6877b5d7c | 2 | Simple DirectMedia Layer |
miruga27 | 0:7fb6877b5d7c | 3 | Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> |
miruga27 | 0:7fb6877b5d7c | 4 | |
miruga27 | 0:7fb6877b5d7c | 5 | This software is provided 'as-is', without any express or implied |
miruga27 | 0:7fb6877b5d7c | 6 | warranty. In no event will the authors be held liable for any damages |
miruga27 | 0:7fb6877b5d7c | 7 | arising from the use of this software. |
miruga27 | 0:7fb6877b5d7c | 8 | |
miruga27 | 0:7fb6877b5d7c | 9 | Permission is granted to anyone to use this software for any purpose, |
miruga27 | 0:7fb6877b5d7c | 10 | including commercial applications, and to alter it and redistribute it |
miruga27 | 0:7fb6877b5d7c | 11 | freely, subject to the following restrictions: |
miruga27 | 0:7fb6877b5d7c | 12 | |
miruga27 | 0:7fb6877b5d7c | 13 | 1. The origin of this software must not be misrepresented; you must not |
miruga27 | 0:7fb6877b5d7c | 14 | claim that you wrote the original software. If you use this software |
miruga27 | 0:7fb6877b5d7c | 15 | in a product, an acknowledgment in the product documentation would be |
miruga27 | 0:7fb6877b5d7c | 16 | appreciated but is not required. |
miruga27 | 0:7fb6877b5d7c | 17 | 2. Altered source versions must be plainly marked as such, and must not be |
miruga27 | 0:7fb6877b5d7c | 18 | misrepresented as being the original software. |
miruga27 | 0:7fb6877b5d7c | 19 | 3. This notice may not be removed or altered from any source distribution. |
miruga27 | 0:7fb6877b5d7c | 20 | */ |
miruga27 | 0:7fb6877b5d7c | 21 | |
miruga27 | 0:7fb6877b5d7c | 22 | /** |
miruga27 | 0:7fb6877b5d7c | 23 | * \file SDL_test_random.h |
miruga27 | 0:7fb6877b5d7c | 24 | * |
miruga27 | 0:7fb6877b5d7c | 25 | * Include file for SDL test framework. |
miruga27 | 0:7fb6877b5d7c | 26 | * |
miruga27 | 0:7fb6877b5d7c | 27 | * This code is a part of the SDL2_test library, not the main SDL library. |
miruga27 | 0:7fb6877b5d7c | 28 | */ |
miruga27 | 0:7fb6877b5d7c | 29 | |
miruga27 | 0:7fb6877b5d7c | 30 | /* |
miruga27 | 0:7fb6877b5d7c | 31 | |
miruga27 | 0:7fb6877b5d7c | 32 | A "32-bit Multiply with carry random number generator. Very fast. |
miruga27 | 0:7fb6877b5d7c | 33 | Includes a list of recommended multipliers. |
miruga27 | 0:7fb6877b5d7c | 34 | |
miruga27 | 0:7fb6877b5d7c | 35 | multiply-with-carry generator: x(n) = a*x(n-1) + carry mod 2^32. |
miruga27 | 0:7fb6877b5d7c | 36 | period: (a*2^31)-1 |
miruga27 | 0:7fb6877b5d7c | 37 | |
miruga27 | 0:7fb6877b5d7c | 38 | */ |
miruga27 | 0:7fb6877b5d7c | 39 | |
miruga27 | 0:7fb6877b5d7c | 40 | #ifndef _SDL_test_random_h |
miruga27 | 0:7fb6877b5d7c | 41 | #define _SDL_test_random_h |
miruga27 | 0:7fb6877b5d7c | 42 | |
miruga27 | 0:7fb6877b5d7c | 43 | #include "begin_code.h" |
miruga27 | 0:7fb6877b5d7c | 44 | /* Set up for C function definitions, even when using C++ */ |
miruga27 | 0:7fb6877b5d7c | 45 | #ifdef __cplusplus |
miruga27 | 0:7fb6877b5d7c | 46 | extern "C" { |
miruga27 | 0:7fb6877b5d7c | 47 | #endif |
miruga27 | 0:7fb6877b5d7c | 48 | |
miruga27 | 0:7fb6877b5d7c | 49 | /* --- Definitions */ |
miruga27 | 0:7fb6877b5d7c | 50 | |
miruga27 | 0:7fb6877b5d7c | 51 | /* |
miruga27 | 0:7fb6877b5d7c | 52 | * Macros that return a random number in a specific format. |
miruga27 | 0:7fb6877b5d7c | 53 | */ |
miruga27 | 0:7fb6877b5d7c | 54 | #define SDLTest_RandomInt(c) ((int)SDLTest_Random(c)) |
miruga27 | 0:7fb6877b5d7c | 55 | |
miruga27 | 0:7fb6877b5d7c | 56 | /* |
miruga27 | 0:7fb6877b5d7c | 57 | * Context structure for the random number generator state. |
miruga27 | 0:7fb6877b5d7c | 58 | */ |
miruga27 | 0:7fb6877b5d7c | 59 | typedef struct { |
miruga27 | 0:7fb6877b5d7c | 60 | unsigned int a; |
miruga27 | 0:7fb6877b5d7c | 61 | unsigned int x; |
miruga27 | 0:7fb6877b5d7c | 62 | unsigned int c; |
miruga27 | 0:7fb6877b5d7c | 63 | unsigned int ah; |
miruga27 | 0:7fb6877b5d7c | 64 | unsigned int al; |
miruga27 | 0:7fb6877b5d7c | 65 | } SDLTest_RandomContext; |
miruga27 | 0:7fb6877b5d7c | 66 | |
miruga27 | 0:7fb6877b5d7c | 67 | |
miruga27 | 0:7fb6877b5d7c | 68 | /* --- Function prototypes */ |
miruga27 | 0:7fb6877b5d7c | 69 | |
miruga27 | 0:7fb6877b5d7c | 70 | /** |
miruga27 | 0:7fb6877b5d7c | 71 | * \brief Initialize random number generator with two integers. |
miruga27 | 0:7fb6877b5d7c | 72 | * |
miruga27 | 0:7fb6877b5d7c | 73 | * Note: The random sequence of numbers returned by ...Random() is the |
miruga27 | 0:7fb6877b5d7c | 74 | * same for the same two integers and has a period of 2^31. |
miruga27 | 0:7fb6877b5d7c | 75 | * |
miruga27 | 0:7fb6877b5d7c | 76 | * \param rndContext pointer to context structure |
miruga27 | 0:7fb6877b5d7c | 77 | * \param xi integer that defines the random sequence |
miruga27 | 0:7fb6877b5d7c | 78 | * \param ci integer that defines the random sequence |
miruga27 | 0:7fb6877b5d7c | 79 | * |
miruga27 | 0:7fb6877b5d7c | 80 | */ |
miruga27 | 0:7fb6877b5d7c | 81 | void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi, |
miruga27 | 0:7fb6877b5d7c | 82 | unsigned int ci); |
miruga27 | 0:7fb6877b5d7c | 83 | |
miruga27 | 0:7fb6877b5d7c | 84 | /** |
miruga27 | 0:7fb6877b5d7c | 85 | * \brief Initialize random number generator based on current system time. |
miruga27 | 0:7fb6877b5d7c | 86 | * |
miruga27 | 0:7fb6877b5d7c | 87 | * \param rndContext pointer to context structure |
miruga27 | 0:7fb6877b5d7c | 88 | * |
miruga27 | 0:7fb6877b5d7c | 89 | */ |
miruga27 | 0:7fb6877b5d7c | 90 | void SDLTest_RandomInitTime(SDLTest_RandomContext *rndContext); |
miruga27 | 0:7fb6877b5d7c | 91 | |
miruga27 | 0:7fb6877b5d7c | 92 | |
miruga27 | 0:7fb6877b5d7c | 93 | /** |
miruga27 | 0:7fb6877b5d7c | 94 | * \brief Initialize random number generator based on current system time. |
miruga27 | 0:7fb6877b5d7c | 95 | * |
miruga27 | 0:7fb6877b5d7c | 96 | * Note: ...RandomInit() or ...RandomInitTime() must have been called |
miruga27 | 0:7fb6877b5d7c | 97 | * before using this function. |
miruga27 | 0:7fb6877b5d7c | 98 | * |
miruga27 | 0:7fb6877b5d7c | 99 | * \param rndContext pointer to context structure |
miruga27 | 0:7fb6877b5d7c | 100 | * |
miruga27 | 0:7fb6877b5d7c | 101 | * \returns A random number (32bit unsigned integer) |
miruga27 | 0:7fb6877b5d7c | 102 | * |
miruga27 | 0:7fb6877b5d7c | 103 | */ |
miruga27 | 0:7fb6877b5d7c | 104 | unsigned int SDLTest_Random(SDLTest_RandomContext *rndContext); |
miruga27 | 0:7fb6877b5d7c | 105 | |
miruga27 | 0:7fb6877b5d7c | 106 | |
miruga27 | 0:7fb6877b5d7c | 107 | /* Ends C function definitions when using C++ */ |
miruga27 | 0:7fb6877b5d7c | 108 | #ifdef __cplusplus |
miruga27 | 0:7fb6877b5d7c | 109 | } |
miruga27 | 0:7fb6877b5d7c | 110 | #endif |
miruga27 | 0:7fb6877b5d7c | 111 | #include "close_code.h" |
miruga27 | 0:7fb6877b5d7c | 112 | |
miruga27 | 0:7fb6877b5d7c | 113 | #endif /* _SDL_test_random_h */ |
miruga27 | 0:7fb6877b5d7c | 114 | |
miruga27 | 0:7fb6877b5d7c | 115 | /* vi: set ts=4 sw=4 expandtab: */ |