Clicky

Fortran Wiki
kiss64 (changes)

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

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

A 64-bit KISS random number generator by George Margaglia, originally posted to comp.lang.fortran in the message 64-bit KISS RNGs. No license was specified.

This version was modified by Jason Blevins to use implicit none and to portably declare the 64-bit/eight-byte integer type.

program test_kiss64
 implicit none
 integer, parameter :: i8b = selected_int_kind(18) ! eight-byte integer
 integer(i8b) :: i, t
 do i = 1, 100000000
 t = (削除) kiss (削除ここまで)(追記) kiss64 (追記ここまで)()
 end do
 if (t .eq. 1666297717051644203_i8b) then
 print *, "100 million calls to KISS() OK"
 else
 print *, "Fail"
 end if
contains
 function kiss64()
 integer(i8b), save :: x, y, z, c
 integer(i8b) :: t, k, m, s, (削除) kiss (削除ここまで)(追記) kiss64 (追記ここまで)
 data x, y, z, c &
 / 1234567890987654321_i8b, &
 362436362436362436_i8b, &
 1066149217761810_i8b, &
 123456123456123456_i8b /
 m(x,k) = ieor(x, ishft(x,k)) ! statement function
 s(x) = ishft(x, -63) ! statement function
 t = ishft(x, 58) + c
 if (s(x) .eq. s(t)) then
 c = ishft(x, -6) + s(x)
 else
 c = ishft(x, -6) + 1 - s(x + t)
 endif
 x = t + x
 y = m(m(m(y,13_i8b),-17_i8b), 43_i8b)
 z = 6906969069_i8b * z + 1234567
 (削除) kiss (削除ここまで)(追記) kiss64 (追記ここまで) = x + y + z
 end function kiss64
end program test_kiss64
Revised on April 14, 2010 21:40:44 by Jason Blevins (75.178.9.182) (1418 characters / 0.0 pages)
Edit | Back in time (2 revisions) | Hide changes | History | Views: Print | TeX | Source | Linked from: Code

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