- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

This isnt a BIG problem, but it might trip someone up if they are not aware of it.

When I call RANDOM_NUMBER(XX) where xx is real(8),

the first value is always a very small number, typically under 1.D-4.

So the first value obtained is not really a **random number.**

Of course can use RANDOM SEED to get around this, but I thought

it was supposed to use the time and date by default.

at any rate, the first number should be as random as all the following ones, right ?

Has this been addressed before ?

Link Copied

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

This question is appropriate for the Fortran compiler forum. Nothing in it pertains to MKL, and note that MKL has its own independent set of routines for random number generation.

It is advisable to consult the documentation of the Fortran intrinsic subroutine RANDOM_NUMBER rather instead of guessing what it does. Details of the RNG are implementation-dependent. The Intel documentation for the 2019 compiler says:

If RANDOM_SEED is not used, the processor sets the seed for RANDOM_NUMBER to a processor-dependent value.

As you discovered, the RNG used in Intel Fortran has a default seed array whose values are always the same. Other Fortran compilers may do this differently. The following program can provide information regarding the RNG for the specific compiler in use.

program trand implicit none integer :: sz integer, allocatable :: s(:) real :: y ! call random_seed(size=sz) print *,'Size = ',sz ! size of seed array allocate(s(sz)) call random_seed(get=s) ! retrieve seeds print '(1x,A,/,(5I15))','Get: ',s deallocate(s) call random_number(y) ! get 1 random number print *,'y = ',y end program

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

I could not find the location of a description for RANDOM_NUMBER.

or RANDOM SEED either.

That's why I posted this forum item.

Furthermore, the routine is GIVEN as an MKL routine.

Is that not correct ?

If they talk about it, I would like to know where - I could not find it.

If you call RANDOM_NUMBER, you will see what I meant by the tiny value

you get back the first time.

Anyway, I will play with your example.

Apparently, there is no way to use the date an time for the random seed,

contradicting the description that we get.

shouldnt it reflect the actual behavior ?

Just for the sake of being correct, anyway.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

In your code example, I dont see where we can set the value of SZ.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

The write-up of this routine is really SLOPPY.

It returns two values of SEED, no matter what I do.

Is it supposed to return a random number for each value of SEED?

It does not do that.

Furthermore, I get the same eentsy-teensy value for the first random number returned

that I got yesterday. Is there an INTEL person I can consult this with ?

At least the write-up should be accurate.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

The size of the SEED array is implementation dependent. For Ifort, it is 2; for Gfortran, it is 33. You have to regard the whole array as the seed, and not attempt to split off one element. In the test program that I provided, the first call to RANDOM_SEED is for the purpose of finding the size of the array. That size is used to allocate the array, and then a second call is made to obtain the RNG's default seed array.

https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-random-number

https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-random-seed

If you wish to use the date, time, etc., to seed the RNG, you have to use that information, with any magic sauce that you want to mix in, to generate the required number of integers to fill the seed array.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

I played around with this -

apparently you are supposed to have a starting value of SEED for each random number

you want back. If you want 10 values of random numbers, the SEED array should have a length of 10.

So, you would input 10 values of SEED. But that does not address the issue of TIME and DATE initializing

the SEED. There is only value for time and date, so how would that give 10 values of SEED?

I think most of you will agree, that if there is a write-up, it should reflect the

* actual behavior* of the routine.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Your speculations in #8 are incorrect. To see that, simply change the line

real :: y

in #3 to

real :: y(7)

and run the program.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

apparently, only 2 items in the SEED array have any bearing on the outcome.

I tried inputing different items 3 thru 10 in the example I gave, it returns the same set of random numbers.

so its puzzling to me that they allow any size array, since that has no bearing on the result.

Since only one value of SEED has any effect, you can only have one sequence of random numbers.

If you input zeros for SEED, then you get that tiny little number to start.

That still does not answer the question -

why does the time and date have no effect if you dont use an input seed?

One can of course call the TIME and DATE routines, and generate the starting seed from that.

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