User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,472 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,777 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 4549 | Replies: 8
Reply
Join Date: Sep 2007
Posts: 3
Reputation: mitzoff is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mitzoff mitzoff is offline Offline
Newbie Poster

Gaussian Random number generator

  #1  
Sep 13th, 2007
I am new to programming in C and I'm trying to write a random number generator with a Gaussian distribution with user-defined mean and variance. I've looked at the code given in "Numerical Recipes in C" but I don't understand it very well. If anyone could point me in the direction of a tutorial or any other help it would be greatly appreciated.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Location: India
Posts: 1,289
Reputation: vishesh is on a distinguished road 
Rep Power: 5
Solved Threads: 32
vishesh's Avatar
vishesh vishesh is offline Offline
Nearly a Posting Virtuoso

Re: Gaussian Random number generator

  #2  
Sep 13th, 2007
What didn't you understand. Try a google search. Here is alink and a sample program:

http://www.taygeta.com/random/gaussian.html
http://www.physics.unlv.edu/~pang/comp2/code213.c
Reply With Quote  
Join Date: Dec 2006
Posts: 232
Reputation: ssharish2005 is on a distinguished road 
Rep Power: 2
Solved Threads: 18
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Gaussian Random number generator

  #3  
Sep 13th, 2007
So which part fo the code u dont understand well? Where did u get the code from?

ssharish
Reply With Quote  
Join Date: Sep 2007
Posts: 3
Reputation: mitzoff is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mitzoff mitzoff is offline Offline
Newbie Poster

Re: Gaussian Random number generator

  #4  
Sep 13th, 2007
When compiling the code given in "Numerical Recipes In C" I get undefined refrecence errors relating to 'main' and the log and sqrt functions. I'm not sure why I'm getting these. I am using gcc in Linux.
Reply With Quote  
Join Date: Dec 2006
Posts: 232
Reputation: ssharish2005 is on a distinguished road 
Rep Power: 2
Solved Threads: 18
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Gaussian Random number generator

  #5  
Sep 13th, 2007
looks like you havn't included the math.h header file. Do this at top

#include <math.h>

ssharish
Reply With Quote  
Join Date: Sep 2004
Posts: 6,515
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 488
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Gaussian Random number generator

  #6  
Sep 13th, 2007
>I get undefined refrecence errors relating to 'main' and the log and sqrt functions. I'm not
>sure why I'm getting these. I am using gcc in Linux.
I'll make an educated guess and say that you didn't link with the math library:
$ gcc main.c -lm
$ ./a.out
I'm here to prove you wrong.
Reply With Quote  
Join Date: Sep 2007
Posts: 3
Reputation: mitzoff is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mitzoff mitzoff is offline Offline
Newbie Poster

Re: Gaussian Random number generator

  #7  
Sep 13th, 2007
I have included math.h. I ran into the same problem when using acos to define pi in another program. When I replaced acos with atan it compiled and worked correctly.
Reply With Quote  
Join Date: Dec 2006
Posts: 232
Reputation: ssharish2005 is on a distinguished road 
Rep Power: 2
Solved Threads: 18
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Gaussian Random number generator

  #8  
Sep 13th, 2007
well, did u try Narue's solution, that could solve the problem as well.

That way you link the library directly to the object file of the code at linking time. And make sure the -lm should be at the end.

ssharish
Last edited by ssharish2005 : Sep 13th, 2007 at 9:32 am.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Gaussian Random number generator

  #9  
Sep 13th, 2007
Originally Posted by mitzoff View Post
I have included math.h. I ran into the same problem when using acos to define pi in another program. When I replaced acos with atan it compiled and worked correctly.


Strange?

#include <stdio.h>
#include <math.h>
#include <string.h>

int main ( void )
{
  float t = acos( 0.3 );
  printf( "%f",t );
  return 0;
}

output
thwee@thwee-desktop:~$ gcc -Wall pedantic.c -lm
thwee@thwee-desktop:~$ ./a.out
1.266104
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 2:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC