Solved

C++ Random integer generation in range 0 - 100000

Posted on 2000-04-29
5
487 Views
Last Modified: 2008-02-20
Could someone please tell me how to generate random integers in the range 0 - 100000 and store them in an array? I have tried rand() but it does not work on integers this large.
Assistance would be appreciated!
0
Comment
Question by:mrarse
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 100 total points
ID: 2762992
You could call rand twice to build your number, but that may not give a very uniform distribution.
Or you might use a different random number generator, e.g. the one described here:
http://www.math.keio.ac.jp/~matumoto/emt.html
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 2763163
0
 
LVL 1

Expert Comment

by:ZivKatzir
ID: 2763314
Hi, you may generate the random numbers
word by word and use pointers to assign them to following memory positions.
Though this may take some time there shouldn't be any problem using this methode in the type of numbers you desire.

In order to avoid the uniformity ozo talked about you should offcourse use the timer er every other changing data to seed the random number generator.
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2763324
Mhh, IMO you should not seed the generator more than once, and surely not after every number generation. That would surely result in a non random sequence.
0
 
LVL 1

Expert Comment

by:ZivKatzir
ID: 2763333
I see that I was miss understood, so let me refine : you should seed the random number generator at the begining of the entire operation using a somewhat changing seed. Moreover a series of random numbers created using the same seed will allways be the same.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question