llrand.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @file llrand.h
  3. * @brief Information, functions, and typedefs for randomness.
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewergpl$
  6. *
  7. * Copyright (c) 2000-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLRAND_H
  33. #define LL_LLRAND_H
  34. #include "llpreprocessor.h"
  35. #include "stdtypes.h"
  36. // *NOTE: The system rand implementation is probably not correct.
  37. #define LL_USE_SYSTEM_RAND 0
  38. /**
  39. * Use the boost random number generators if you want a stateful
  40. * random numbers. If you want more random numbers, use the
  41. * C-functions since they will generate faster/better randomness
  42. * across the process.
  43. *
  44. * I tested some of the boost random engines, and picked a good double
  45. * generator and a good integer generator. I also took some timings
  46. * for them on Linux using gcc 3.3.5. The harness also did some other
  47. * fairly trivial operations to try to limit compiler optimizations,
  48. * so these numbers are only good for relative comparisons.
  49. *
  50. * usec/inter algorithm
  51. * 0.21 boost::minstd_rand0
  52. * 0.039 boost:lagged_fibonacci19937
  53. * 0.036 boost:lagged_fibonacci607
  54. * 0.44 boost::hellekalek1995
  55. * 0.44 boost::ecuyer1988
  56. * 0.042 boost::rand48
  57. * 0.043 boost::mt11213b
  58. * 0.028 stdlib random()
  59. * 0.05 stdlib lrand48()
  60. * 0.034 stdlib rand()
  61. * 0.020 the old & lame LLRand
  62. */
  63. // Generates a float from [0, RAND_MAX).
  64. S32 ll_rand();
  65. // Generates a float from [0, val) or (val, 0].
  66. S32 ll_rand(S32 val);
  67. // Generates a float from [0, 1.0).
  68. F32 ll_frand();
  69. // Generates a float from [0, val) or (val, 0].
  70. F32 ll_frand(F32 val);
  71. // Generates a double from [0, 1.0).
  72. F64 ll_drand();
  73. // Generates a double from [0, val) or (val, 0].
  74. F64 ll_drand(F64 val);
  75. #endif