Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C++ Random integer generation in range 0 - 100000

Posted on 2000-04-29
5
Medium Priority
?
507 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
5 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 300 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

877 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