Continue to Site

# Anyone here used Fortran be4?

Status
Not open for further replies.

#### cwjcwjcwj

##### Full Member level 5
I am a begineer in Fortran,but I am experienced in Matlab. Just wanna know, what is the main purpose of the following command in Fortran:

igene=2*int(13*secnds(0.0))+1968
call SRand(igene)

Thanks!Actually, I am not really know what is secnds(0.0) and SRand. The rest of them are pretty simple.I know that this is a random number generation.

Hi,
Oh, it was at leat 17 years ago I toucht that aqfull language!

Anyway, if I remeber it right, secnds(0.0) will return a value of seconds with 1 decimal accuracy, and Srand is a random generator.

So basicly, what you are doing is to create a good random number with the seed value based on the current time, so you will never have the same seed number for Pseudo Random Generator.

https://gcc.gnu.org/onlinedocs/gcc-3.4.3/g77/Secnds-Intrinsic.html

https://gcc.gnu.org/onlinedocs/gcc-3.4.3/g77/SRand-Intrinsic.html

Hope it helps,

BR,

### cwjcwjcwj

Points: 2

#### cwjcwjcwj

##### Full Member level 5
Thanks.So is it possible to convert it to Matlab Language?

Hi,
Glad to be able to help. I am not so god with Mathlab, and I have no idea if there is a similar function in MatLab, that returns the current time in seconds, but do a quick search on gogle gave this:

https://www.mathworks.com/access/helpdesk/help/techdoc/ref/clock.html

You maybe able to get the current time in seconds, but I don't think it is as accurate as the fortran function.

Have a look at the random function of MatLab:

https://www.mathworks.com/access/helpdesk/help/techdoc/ref/rand.html#998321

MAybe there is someone else with a better knowledge of Matlab who can give you a better answer.

BR,

### cwjcwjcwj

Points: 2

#### zorro

Hi friends,

In Matlab, use the clock function in order to read the current time.
In order to start the random generator with a “random” seed, use as follows in Matlab version 5 or more:

rand('state',sum(100*clock));

Regards

Z

### cwjcwjcwj

Points: 2

#### cwjcwjcwj

##### Full Member level 5
Thanks alot friends.So if it is the case.I will need to write as below to generate 10 random numbers,based on the clock. Pls help to clarify.

rand('state',sum(100*clock));
rand_num=rand(1,10);

Am I right?

##### Full Member level 3
>>rand('state',sum(100*clock))
>>uniform_random_number = unidrnd(10) // or = random('Discrete Uniform',10)

This generate the discrete uniform random number {1,...,10}.
The first line is only necessary for matlab to generate different random sequence when the program is restarted.

Try to use "help" in matlab to find information.
>> help random
>> help rand
and et.

Points: 2