Random number generators

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2009
Posts: 1
Reputation: somyasinha is an unknown quantity at this point 
Solved Threads: 0
somyasinha somyasinha is offline Offline
Newbie Poster

Re: Random number generator's

 
0
  #1
Jul 6th, 2009
Hi,

How do I use the generator in the file? I keep randomc.h as a header file in the Visual c++ project. My project has several header files and several .cpp files, many of which require to use the random no. generator. I have copied all the files in the zip folder into the folder for my project files.
Do I write this in each file that uses the generator?

  1. #ifndef MULTIFILE_PROJECT
  2. // If compiled as a single file then include these cpp files,
  3. // If compiled as a project then compile and link in these cpp files.
  4. // Include code for the chosen random number generator:
  5. #include "mersenne.cpp"
  6. // define system specific user interface:
  7. #include "userintf.cpp"
  8. #endif
  9.  
  10.  
  11. #include <time.h> // define time()
  12. #include "randomc.h"

The compling is ok. But I get a lot of linking errors, e.g.,

GABaseSolver.obj : error LNK2005: "private: void __thiscall CRandomMersenne::Init0(int)" (?Init0@CRandomMersenne@@AAEXH@Z) already defined in GA1DArraySolution.obj
Please help.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 219
Reputation: NathanOliver is an unknown quantity at this point 
Solved Threads: 37
NathanOliver's Avatar
NathanOliver NathanOliver is offline Offline
Posting Whiz in Training

Re: Random number generators

 
0
  #2
Jul 6th, 2009
in every header file it is a good idea to use inclusion guards. so to stop it from getting defined all the time just put
  1. #ifndef RANDOMC_H
  2. #define RANDOMC_H
  3. // all the code in randomc.h goes here
  4. #endif
this will make sure that the file is only included the first time and every other time #include "randomc.h" is encountered the compiler will skip that file because it is already defined. I've found this makes things easier down the road and saves some debugging time.
if you write using namespace std; you do not need to write std::something in your program.
If your thread is solved please mark it as solved
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 117
Reputation: u8sand is on a distinguished road 
Solved Threads: 15
u8sand's Avatar
u8sand u8sand is offline Offline
Junior Poster

Re: Random number generators

 
0
  #3
Jul 6th, 2009
Some compilers that are stupid the gaurds still wont work, if that is so try using pragma once at the top.
  1. #pragma once
Last edited by u8sand; Jul 6th, 2009 at 8:44 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC