program test_mtprng !--------------------------------------------------------------------- ! From the Algorithmic Conjurings of Scott Robert Ladd comes... !--------------------------------------------------------------------- ! ! test_mtprng.f90 ! ! A program for testing the mtprng (Mersenne Twister) module. ! !--------------------------------------------------------------------- ! ! COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: ! ! This notice applies *only* to this specific expression of this ! algorithm, and does not imply ownership or invention of the ! implemented algorithm. ! ! If you modify this file, you may insert additional notices ! immediately following this sentence. ! ! Copyright 2001, 2002, 2004 Scott Robert Ladd. ! All rights reserved, except as noted herein. ! ! This computer program source file is supplied "AS IS". Scott Robert ! Ladd (hereinafter referred to as "Author") disclaims all warranties, ! expressed or implied, including, without limitation, the warranties ! of merchantability and of fitness for any purpose. The Author ! assumes no liability for direct, indirect, incidental, special, ! exemplary, or consequential damages, which may result from the use ! of this software, even if advised of the possibility of such damage. ! ! The Author hereby grants anyone permission to use, copy, modify, and ! distribute this source code, or portions hereof, for any purpose, ! without fee, subject to the following restrictions: ! ! 1. The origin of this source code must not be misrepresented. ! ! 2. Altered versions must be plainly marked as such and must not ! be misrepresented as being the original source. ! ! 3. This Copyright notice may not be removed or altered from any ! source or altered source distribution. ! ! The Author specifically permits (without fee) and encourages the use ! of this source code for entertainment, education, or decoration. If ! you use this source code in a product, acknowledgment is not required ! but would be appreciated. ! ! Acknowledgement: ! This license is based on the wonderful simple license that ! accompanies libpng. ! !----------------------------------------------------------------------- ! ! For more information on this software package, please visit ! Scott's web site, Coyote Gulch Productions, at: ! ! http://www.coyotegulch.com ! !----------------------------------------------------------------------- use stdtypes use mtprng implicit none integer, parameter :: TEST_SIZE = 2000000000 integer(INT64) x64, max64, min64 integer :: i, j, count, count_rate, count_max, x, total real(IEEE64) :: n, l, s integer, dimension(10) :: counts character(*), parameter :: fmt1 = "(A,F30.27)" type(mtprng_state) :: state !call system_clock(count,count_rate,count_max) call mtprng_init(1,state) min64 = HUGE(INT32) max64 = -min64 do i = 1, TEST_SIZE x64 = mtprng_rand64(state) if (x64 < min64) min64 = x64 if (x64 > max64) max64 = x64 end do write(*,*) 'min 64 = ', min64 write(*,*) 'max 64 = ', max64 ! each real function write(*,*) write(*,*) 'mtprng_rand_real1 - interval [0,1]' s = huge(IEEE64) l = -s do i = 1, TEST_SIZE n = mtprng_rand_real1(state) if (n < s) s = n if (n > l) l = n end do write(*,fmt1) " largest = ", l write(*,fmt1) " smallest = ", s ! each real function write(*,*) write(*,*) 'mtprng_rand_real2 - interval [0,1)' s = huge(IEEE64) l = -s do i = 1, TEST_SIZE n = mtprng_rand_real2(state) if (n < s) s = n if (n > l) l = n end do write(*,fmt1) " largest = ", l write(*,fmt1) " smallest = ", s ! each real function write(*,*) write(*,*) 'mtprng_rand_real3 - interval (0,1)' s = huge(IEEE64) l = -s do i = 1, TEST_SIZE n = mtprng_rand_real3(state) if (n < s) s = n if (n > l) l = n end do write(*,fmt1) " largest = ", l write(*,fmt1) " smallest = ", s ! check ranges counts = 0 do i = 1, TEST_SIZE x = mtprng_rand_range(state,1,size(counts)) counts(x) = counts(x) + 1 end do write (*,*) " " total = 0 do i = 1, size(counts) write(*,*) "counts ", i, " = ", counts(i) total = total + counts(i) end do write (*,*) "total = ", total end program test_mtprng