Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C++ Random integer generation in range 0 - 100000

Posted on 2000-04-29
5
Medium Priority
?
499 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

688 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