×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# random number in interval of [-1,+1]

## random number in interval of [-1,+1]

(OP)
Hi everyone,
I'm a new user of FORTRAN and i would like to write a subroutine in fortran to generate a random number between [-1 , +1]
actually i have written a simple one but , the number generated is between [0, +1] and in each time of compilation i have the same random number generated

i need help to fix this problem

### RE: random number in interval of [-1,+1]

Hi Am_Ine,

You can generate random number 0 <= r <= 1 using the subroutine random_number(r)

Then if you have r from [0, 1] then you can create a random number q from [A, B] as
q = A + (B - A) * r
so in your case for q from [-1 1] it will be
q = -1 + 2 * r

### RE: random number in interval of [-1,+1]

(OP)
sorry but , please i have just one more question,
to generate differente random numbers each compilation , the function'' init_random-seed()'' doesn't works with me
i get :

/tmp/cc4kPuvl.o: In function MAIN__':
main.f95:(.text+0x18): undefined reference to init_random_seed_'
collect2: error: ld returned 1 exit status

do you have anby solution for that

### RE: random number in interval of [-1,+1]

(OP)
thank you mikrom for your help

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!