View Single Post
Old Feb 11th, 2008, 3:30 PM   #5
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: random numbers fortran 90

x(i)=x(j)
x(j)=x(i)

That is close, but examine what happens when you swap two elements. The value of the first element is overwritten, by the time you assign it a new value.

E.G. Let x(i) be 5, and x(j) be 6.

x(i) becomes x(j) = 6
x(j) becomes x(i) = 6 as well

The solution to this is to use a temporary variable, let's say temp, to remember the first value, before the swapping occurs.

temp = x(i)
x(i) = x(j)
x(j) = temp
Sane is online now   Reply With Quote