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.

dlarnd.f 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. *> \brief \b DLARND
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * DOUBLE PRECISION FUNCTION DLARND( 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. *> DLARND 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. *> \ingroup double_matgen
  60. *
  61. *> \par Further Details:
  62. * =====================
  63. *>
  64. *> \verbatim
  65. *>
  66. *> This routine calls the auxiliary routine DLARAN to generate a random
  67. *> real number from a uniform (0,1) distribution. The Box-Muller method
  68. *> is used to transform numbers from a uniform to a normal distribution.
  69. *> \endverbatim
  70. *>
  71. * =====================================================================
  72. DOUBLE PRECISION FUNCTION DLARND( IDIST, ISEED )
  73. *
  74. * -- LAPACK auxiliary routine --
  75. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  76. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  77. *
  78. * .. Scalar Arguments ..
  79. INTEGER IDIST
  80. * ..
  81. * .. Array Arguments ..
  82. INTEGER ISEED( 4 )
  83. * ..
  84. *
  85. * =====================================================================
  86. *
  87. * .. Parameters ..
  88. DOUBLE PRECISION ONE, TWO
  89. PARAMETER ( ONE = 1.0D+0, TWO = 2.0D+0 )
  90. DOUBLE PRECISION TWOPI
  91. PARAMETER ( TWOPI = 6.28318530717958647692528676655900576839D+0 )
  92. * ..
  93. * .. Local Scalars ..
  94. DOUBLE PRECISION T1, T2
  95. * ..
  96. * .. External Functions ..
  97. DOUBLE PRECISION DLARAN
  98. EXTERNAL DLARAN
  99. * ..
  100. * .. Intrinsic Functions ..
  101. INTRINSIC COS, LOG, SQRT
  102. * ..
  103. * .. Executable Statements ..
  104. *
  105. * Generate a real random number from a uniform (0,1) distribution
  106. *
  107. T1 = DLARAN( ISEED )
  108. *
  109. IF( IDIST.EQ.1 ) THEN
  110. *
  111. * uniform (0,1)
  112. *
  113. DLARND = T1
  114. ELSE IF( IDIST.EQ.2 ) THEN
  115. *
  116. * uniform (-1,1)
  117. *
  118. DLARND = TWO*T1 - ONE
  119. ELSE IF( IDIST.EQ.3 ) THEN
  120. *
  121. * normal (0,1)
  122. *
  123. T2 = DLARAN( ISEED )
  124. DLARND = SQRT( -TWO*LOG( T1 ) )*COS( TWOPI*T2 )
  125. END IF
  126. RETURN
  127. *
  128. * End of DLARND
  129. *
  130. END