help with random 
Author Message
 help with random

Hi,

I tried my hand at fortran 77 to obtain arbitrarily large random
numbers distributed in a certain way. At one point, these lines appear
in my code:

      ...
      lx=ran2(seed)
      fix=TAN(pi*lx)
      print *, fix
      fc=fcov(fix)
      ...

That print statement was to ensure 'fix' took good values. But later I
found the program gave wrong output if the print statement were not
there. Surprising; for the print has got nothing to do with the random
number generation. What's happening?

Girish



Tue, 22 Jul 2008 03:50:26 GMT  
 help with random

Quote:

> Hi,

> I tried my hand at Fortran 77 to obtain arbitrarily large random
> numbers distributed in a certain way. At one point, these lines appear
> in my code:

>       ...
>       lx=ran2(seed)
>       fix=TAN(pi*lx)
>       print *, fix
>       fc=fcov(fix)
>       ...

> That print statement was to ensure 'fix' took good values. But later I
> found the program gave wrong output if the print statement were not
> there. Surprising; for the print has got nothing to do with the random
> number generation. What's happening?

> Girish

Of course it is difficult to determine with so little code, but my
guess, if indeed things are as you describe them, is that you have a
bug elsewhere. Perhaps removing the print statement trashes something
at a *different spot* in memory, so IMO the chief suspects are:

array access out of bounds
uninitialized variable
argument mismatch to sub-program

Find and turn on your compiler's source checking and run-time debugging
options. For good measure, (if it is Fortran 77), run it through
FTNCHEK.

-- Elliot



Tue, 22 Jul 2008 04:11:42 GMT  
 help with random

Quote:
> Of course it is difficult to determine with so little code, but my
> guess, if indeed things are as you describe them, is that you have a
> bug elsewhere.

That would also be my guess. It is very common, when someone asks for
help with a bug, for them to show parts of the code that actually don't
have anything to do with the bug. After all, if they really understood
exactly what was happening, they wouldn't need to ask for help.

Just because changing soemthing in this part of the code changes the
results, that does not mean that the actual bug is here (as Elliot
explained).

The business about printing fix to "ensure that it took good values"
doesn't hold up. It is posssible for things vaguely like that to happen,
where a variable gets "optimized away" if it isn't used, and printing it
changes that. But that explanation doesn't fit the code shown, as fix is
used anyway in the very next line.

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain



Tue, 22 Jul 2008 06:44:25 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help with Random numbers, please

2. help on random

3. Help: Pseudo-random Sequenece Verification

4. Need help with random numbers

5. need help in random numbers.

6. Help please: Random numbers and graphics

7. help with random file access using CA REALIA

8. need help on random number

9. help with random number

10. Help with random record!

11. help: generating random no

12. HELP needed: RANDOM NUMBER GENERATION

 

 
Powered by phpBB® Forum Software