-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrandom_initialize.f90
More file actions
100 lines (89 loc) · 2.34 KB
/
random_initialize.f90
File metadata and controls
100 lines (89 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
subroutine random_initialize ( seed )
!*****************************************************************************80
!
!! RANDOM_INITIALIZE initializes the FORTRAN90 random number seed.
!
! Discussion:
!
! If you don't initialize the random number generator, its behavior
! is not specified. If you initialize it simply by:
!
! call random_seed ( )
!
! its behavior is not specified. On the DEC ALPHA, if that's all you
! do, the same random number sequence is returned. In order to actually
! try to scramble up the random number generator a bit, this routine
! goes through the tedious process of getting the size of the random
! number seed, making up values based on the current time, and setting
! the random number seed.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 03 April 2001
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input/output, integer SEED.
! If SEED is zero on input, then you're asking this routine to come up
! with a seed value, which is returned as output.
! If SEED is nonzero on input, then you're asking this routine to
! use the input value of SEED to initialize the random number generator.
!
implicit none
integer count
integer count_max
integer count_rate
integer i
integer seed
integer, allocatable :: seed_vector(:)
integer seed_size
double precision t
!
! Initialize the random number seed.
!
call random_seed ( )
!
! Determine the size of the random number seed.
!
call random_seed ( size = seed_size )
!
! Allocate a seed of the right size.
!
allocate ( seed_vector(seed_size) )
if ( seed /= 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'RANDOM_INITIALIZE'
write ( *, '(a,i12)' ) ' Initialize RANDOM_NUMBER with user SEED = ', seed
else
call system_clock ( count, count_rate, count_max )
seed = count
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'RANDOM_INITIALIZE'
write ( *, '(a,i12)' ) &
' Initialize RANDOM_NUMBER with arbitrary SEED = ', seed
end if
!
! Now set the seed.
!
seed_vector(1:seed_size) = seed
call random_seed ( put = seed_vector(1:seed_size) )
!
! Free up the seed space.
!
deallocate ( seed_vector )
!
! Call the random number routine a bunch of times.
!
do i = 1, 100
call random_number ( harvest = t )
end do
return
end