| | |
Random number generators
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2009
Posts: 1
Reputation:
Solved Threads: 0
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?
The compling is ok. But I get a lot of linking errors, e.g.,
Please help.
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?
C++ Syntax (Toggle Plain Text)
#ifndef MULTIFILE_PROJECT // If compiled as a single file then include these cpp files, // If compiled as a project then compile and link in these cpp files. // Include code for the chosen random number generator: #include "mersenne.cpp" // define system specific user interface: #include "userintf.cpp" #endif #include <time.h> // define time() #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
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
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.
c++ Syntax (Toggle Plain Text)
#ifndef RANDOMC_H #define RANDOMC_H // all the code in randomc.h goes here #endif
if you write
If your thread is solved please mark it as solved
using namespace std; you do not need to write std::something in your program.If your thread is solved please mark it as solved
Some compilers that are stupid the gaurds still wont work, if that is so try using pragma once at the top.
C++ Syntax (Toggle Plain Text)
#pragma once
Last edited by u8sand; Jul 6th, 2009 at 8:44 pm.
![]() |
Similar Threads
- True Random Number Generator (C++)
- Random number generator's (C++)
- Random number Sequence Generation (C++)
- Question about Random Number Generators (C++)
- using random number generator "globally" in a c++ class (C++)
- help with this assigment please..it's ARGENT..! (C++)
- Logic behind generating random number (C)
Other Threads in the C++ Forum
- Previous Thread: Need help initializing variables
- Next Thread: Checking if variable is a number or a letter: Error
Views: 297 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





