Solved

C++ Random integer generation in range 0 - 100000

Posted on 2000-04-29
5
493 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

615 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