25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

SDL_test_random.h 3.1 KiB

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