The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_RANDOM_JUCEHEADER__
  19. #define __JUCE_RANDOM_JUCEHEADER__
  20. #include "../containers/juce_BitArray.h"
  21. //==============================================================================
  22. /**
  23. A simple pseudo-random number generator.
  24. */
  25. class JUCE_API Random
  26. {
  27. public:
  28. //==============================================================================
  29. /** Creates a Random object based on a seed value.
  30. For a given seed value, the subsequent numbers generated by this object
  31. will be predictable, so a good idea is to set this value based
  32. on the time, e.g.
  33. new Random (Time::currentTimeMillis())
  34. */
  35. Random (int64 seedValue) throw();
  36. /** Destructor. */
  37. ~Random() throw();
  38. /** Returns the next random 32 bit integer.
  39. @returns a random integer from the full range 0x80000000 to 0x7fffffff
  40. */
  41. int nextInt() throw();
  42. /** Returns the next random number, limited to a given range.
  43. @returns a random integer between 0 (inclusive) and maxValue (exclusive).
  44. */
  45. int nextInt (int maxValue) throw();
  46. /** Returns the next 64-bit random number.
  47. @returns a random integer from the full range 0x8000000000000000 to 0x7fffffffffffffff
  48. */
  49. int64 nextInt64() throw();
  50. /** Returns the next random floating-point number.
  51. @returns a random value in the range 0 to 1.0
  52. */
  53. float nextFloat() throw();
  54. /** Returns the next random floating-point number.
  55. @returns a random value in the range 0 to 1.0
  56. */
  57. double nextDouble() throw();
  58. /** Returns the next random boolean value.
  59. */
  60. bool nextBool() throw();
  61. /** Returns a BigInteger containing a random number.
  62. @returns a random value in the range 0 to (maximumValue - 1).
  63. */
  64. const BigInteger nextLargeNumber (const BigInteger& maximumValue);
  65. /** Sets a range of bits in a BigInteger to random values. */
  66. void fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numBits);
  67. //==============================================================================
  68. /** To avoid the overhead of having to create a new Random object whenever
  69. you need a number, this is a shared application-wide object that
  70. can be used.
  71. It's not thread-safe though, so threads should use their own Random object.
  72. */
  73. static Random& getSystemRandom() throw();
  74. /** Resets this Random object to a given seed value. */
  75. void setSeed (int64 newSeed) throw();
  76. /** Merges this object's seed with another value.
  77. This sets the seed to be a value created by combining the current seed and this
  78. new value.
  79. */
  80. void combineSeed (int64 seedValue) throw();
  81. /** Reseeds this generator using a value generated from various semi-random system
  82. properties like the current time, etc.
  83. Because this function convolves the time with the last seed value, calling
  84. it repeatedly will increase the randomness of the final result.
  85. */
  86. void setSeedRandomly();
  87. //==============================================================================
  88. juce_UseDebuggingNewOperator
  89. private:
  90. int64 seed;
  91. };
  92. #endif // __JUCE_RANDOM_JUCEHEADER__