Clicky

Fortran Wiki
init_seed (changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #0 to #1: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

This subroutine is from a post on comp.lang.fortran.

subroutine init_seed()
 integer :: n, ival(8), v(3), i
 integer, allocatable :: seed(:)
 call date_and_time(values=ival)
 v(1) = ival(8) + 2048*ival(7)
 v(2) = ival(6) + 64*ival(5) ! value(4) isn't really 'random'
 v(3) = ival(3) + 32*ival(2) + 32*8*ival(1)
 call random_seed(size=n)
 allocate(seed(n))
 call random_seed() ! Give the seed an implementation-dependent kick
 call random_seed(get=seed)
 do i=1, n
 seed(i) = seed(i) + v(mod(i-1, 3) + 1)
 enddo
 call random_seed(put=seed)
 deallocate(seed)
end subroutine

category: code

Created on April 28, 2009 14:37:55 by Jason Blevins (152.3.10.27) (766 characters / 0.0 pages)
Edit | Views: Print | TeX | Source | Linked from: Code, 2009

AltStyle によって変換されたページ (->オリジナル) /