You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

slarnd.f 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. *> \brief \b SLARND
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * REAL FUNCTION SLARND( IDIST, ISEED )
  12. *
  13. * .. Scalar Arguments ..
  14. * INTEGER IDIST
  15. * ..
  16. * .. Array Arguments ..
  17. * INTEGER ISEED( 4 )
  18. * ..
  19. *
  20. *
  21. *> \par Purpose:
  22. * =============
  23. *>
  24. *> \verbatim
  25. *>
  26. *> SLARND returns a random real number from a uniform or normal
  27. *> distribution.
  28. *> \endverbatim
  29. *
  30. * Arguments:
  31. * ==========
  32. *
  33. *> \param[in] IDIST
  34. *> \verbatim
  35. *> IDIST is INTEGER
  36. *> Specifies the distribution of the random numbers:
  37. *> = 1: uniform (0,1)
  38. *> = 2: uniform (-1,1)
  39. *> = 3: normal (0,1)
  40. *> \endverbatim
  41. *>
  42. *> \param[in,out] ISEED
  43. *> \verbatim
  44. *> ISEED is INTEGER array, dimension (4)
  45. *> On entry, the seed of the random number generator; the array
  46. *> elements must be between 0 and 4095, and ISEED(4) must be
  47. *> odd.
  48. *> On exit, the seed is updated.
  49. *> \endverbatim
  50. *
  51. * Authors:
  52. * ========
  53. *
  54. *> \author Univ. of Tennessee
  55. *> \author Univ. of California Berkeley
  56. *> \author Univ. of Colorado Denver
  57. *> \author NAG Ltd.
  58. *
  59. *> \date December 2016
  60. *
  61. *> \ingroup real_matgen
  62. *
  63. *> \par Further Details:
  64. * =====================
  65. *>
  66. *> \verbatim
  67. *>
  68. *> This routine calls the auxiliary routine SLARAN to generate a random
  69. *> real number from a uniform (0,1) distribution. The Box-Muller method
  70. *> is used to transform numbers from a uniform to a normal distribution.
  71. *> \endverbatim
  72. *>
  73. * =====================================================================
  74. REAL FUNCTION SLARND( IDIST, ISEED )
  75. *
  76. * -- LAPACK auxiliary routine (version 3.7.0) --
  77. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  78. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  79. * December 2016
  80. *
  81. * .. Scalar Arguments ..
  82. INTEGER IDIST
  83. * ..
  84. * .. Array Arguments ..
  85. INTEGER ISEED( 4 )
  86. * ..
  87. *
  88. * =====================================================================
  89. *
  90. * .. Parameters ..
  91. REAL ONE, TWO
  92. PARAMETER ( ONE = 1.0E+0, TWO = 2.0E+0 )
  93. REAL TWOPI
  94. PARAMETER ( TWOPI = 6.2831853071795864769252867663E+0 )
  95. * ..
  96. * .. Local Scalars ..
  97. REAL T1, T2
  98. * ..
  99. * .. External Functions ..
  100. REAL SLARAN
  101. EXTERNAL SLARAN
  102. * ..
  103. * .. Intrinsic Functions ..
  104. INTRINSIC COS, LOG, SQRT
  105. * ..
  106. * .. Executable Statements ..
  107. *
  108. * Generate a real random number from a uniform (0,1) distribution
  109. *
  110. T1 = SLARAN( ISEED )
  111. *
  112. IF( IDIST.EQ.1 ) THEN
  113. *
  114. * uniform (0,1)
  115. *
  116. SLARND = T1
  117. ELSE IF( IDIST.EQ.2 ) THEN
  118. *
  119. * uniform (-1,1)
  120. *
  121. SLARND = TWO*T1 - ONE
  122. ELSE IF( IDIST.EQ.3 ) THEN
  123. *
  124. * normal (0,1)
  125. *
  126. T2 = SLARAN( ISEED )
  127. SLARND = SQRT( -TWO*LOG( T1 ) )*COS( TWOPI*T2 )
  128. END IF
  129. RETURN
  130. *
  131. * End of SLARND
  132. *
  133. END