Solved

C++ Random integer generation in range 0 - 100000

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

Accepted Solution

by:
ozo earned 100 total points
Comment Utility
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
Comment Utility
0
 
LVL 1

Expert Comment

by:ZivKatzir
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 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 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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now