- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, guys:
I want to create a random number with Gaussian distribution probability by function vsrnggaussian.
The subroutine is:
INCLUDE '/home/fengy/mkl/10.0.3.020/include/mkl_vsl.fi'
INCLUDE '/home/fengy/mkl/10.0.3.020/examples/vslf/source/errcheck.inc'
SUBROUTINE test_sub1
USE MKL_VSL_TYPE
USE MKL_VSL
IMPLICIT NONE
REAL, DIMENSION(1) :: r
INTEGER(KIND=4) i, nn
INTEGER n
INTEGER(KIND=4) errcode
INTEGER brng, method, seed
TYPE(VSL_STREAM_STATE) :: stream
REAL a, sigma
n=1
brng = VSL_BRNG_MCG31
method = 0
seed = 777
a = 0.0
sigma = 1.0
errcode = vslnewstream(stream, brng, seed)
CALL CheckVslError(errcode)
errcode = vsrnggaussian(method, stream, n, r, a, sigma)
CALL CheckVslError(errcode)
WRITE(*,*) 'now r is: ', r(1)
END SUBROUTINE test_sub1
The main program is:
PROGRAM test_g_r
IMPLICIT NONE
INTEGER n
REAL, DIMENSION(1) :: r
DO n=1, 10
CALL test_sub1
ENDDO
END PROGRAM test_g_r
However, the output of r(1) does not change. It is a intrinsic problem for function vsrnggaussian? What can I do so that each time test_sub1 is called, it will give a random number which has Gaussian distribution density?
Thanks!
Arthur
I want to create a random number with Gaussian distribution probability by function vsrnggaussian.
The subroutine is:
INCLUDE '/home/fengy/mkl/10.0.3.020/include/mkl_vsl.fi'
INCLUDE '/home/fengy/mkl/10.0.3.020/examples/vslf/source/errcheck.inc'
SUBROUTINE test_sub1
USE MKL_VSL_TYPE
USE MKL_VSL
IMPLICIT NONE
REAL, DIMENSION(1) :: r
INTEGER(KIND=4) i, nn
INTEGER n
INTEGER(KIND=4) errcode
INTEGER brng, method, seed
TYPE(VSL_STREAM_STATE) :: stream
REAL a, sigma
n=1
brng = VSL_BRNG_MCG31
method = 0
seed = 777
a = 0.0
sigma = 1.0
errcode = vslnewstream(stream, brng, seed)
CALL CheckVslError(errcode)
errcode = vsrnggaussian(method, stream, n, r, a, sigma)
CALL CheckVslError(errcode)
WRITE(*,*) 'now r is: ', r(1)
END SUBROUTINE test_sub1
The main program is:
PROGRAM test_g_r
IMPLICIT NONE
INTEGER n
REAL, DIMENSION(1) :: r
DO n=1, 10
CALL test_sub1
ENDDO
END PROGRAM test_g_r
However, the output of r(1) does not change. It is a intrinsic problem for function vsrnggaussian? What can I do so that each time test_sub1 is called, it will give a random number which has Gaussian distribution density?
Thanks!
Arthur
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your program creates and initializes random stream with the same basic random generator and seed 10 times in subroutine test_sub1. So, output of the Gaussian generator is not changed. Can you create/initialize random stream once in your main program andpass the stream in the subroutine test_sub1? Please, do not forget to remove initialization of the stream in the sub-routine.Also, please free resources allocated for random stream in the main programwhengeneration of random numbers is completed.Routine vsldeletestream can be used for this purpose. Thanks, Andrey

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page