I think, a simple C question - HELP NEEDED 
Author Message
 I think, a simple C question - HELP NEEDED

*  Any body familier with Numerical Recipes in C .... it's page 283

  Hello,

    I am a VERY, VERY inexperienced beginning C person.  (can't really
call myself a programmer)

    I am tyring to use a routine in the Numerical Recipes in C book to
write a program that calculates definate integrals by the Monte Carlo
method.

    Anyway my question is very simple...

The function in Num. Rec. in C is called  ran3 and I CAN NOT for the life
of me extract a random number from the routine.....

If I have a routine that looks like this....
===============================================

float ran3(long *idum)

{...........   return mj*FAC; }

How would I properly write a main() that calls the function and returns
the result that ran3 produces.

I think I'm having a hard time dealing with the 'long *idum'

The Num.Rec.in.C says  "Set idum to any negative value to initialize or
reinitialize the sequence"

I don't know what to do.....


 _____________________________
/ Mark Decker                 \  2026 AD

| Physics, CREOL -UCF         |  inflection point)
|                             |
| www.creol.ucf.edu/~madecker |  There is too much life
\_____________________________/   and not enough death.



Tue, 28 Apr 1998 03:00:00 GMT  
 I think, a simple C question - HELP NEEDED


<snip>
|>     I am a VERY, VERY inexperienced beginning C person.  (can't really
|> call myself a programmer)

Sometimes, it is easier to learn the language _before_ programming. Really!
It is true! A little time wasted when you can't afford it at all, saves a lot
of time wasted when you can afford it even less.

<snip>
|> float ran3(long *idum)
|>
|> {...........   return mj*FAC; }
|>
|>
|>
|> How would I properly write a main() that calls the function and returns
|> the result that ran3 produces.
|>
|> I think I'm having a hard time dealing with the 'long *idum'
|>
|> The Num.Rec.in.C says  "Set idum to any negative value to initialize or
|> reinitialize the sequence"

Declare

long idum = -1;

and then keep using ran3(&idum);

Cheers
Tanmoy
--

Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]



Wed, 29 Apr 1998 03:00:00 GMT  
 I think, a simple C question - HELP NEEDED

Quote:
>*  Any body familier with Numerical Recipes in C .... it's page 283

>If I have a routine that looks like this....
>===============================================

>float ran3(long *idum)

>{...........   return mj*FAC; }

>How would I properly write a main() that calls the function and returns
>the result that ran3 produces.

#include <stdio.h>
/* your code and includes */
int main( void )
{
   long  seed = -1;
   int    i;
   /* print 10 "randoms" */
   for ( i = 0; i < 10; i++ )
      printf( "%f\n", ran3( &seed ) );
   return 0;

Quote:
}

Bill McCarthy
Wendell, NC


Wed, 29 Apr 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Beginner needs to compile a simple program in Think C.

2. Newbie to ADO with C++Simple Question (I thinks)

3. Very simple question ( I think)

4. Simple Biginners question....I think

5. Simple (i think) Question....

6. Simple question (or so I thought)

7. really simple question (I think)

8. newbe/cs student, need help w/ code

9. Help... V Simple Questions Need Answering

10. Newbie needs urgent help, simple question

11. Simple Question - NEED HELP!!!

12. A Simple Question, Need Help!

 

 
Powered by phpBB® Forum Software