Solved

Generating different sequences of random numbers

Posted on 2000-02-15
8
226 Views
Last Modified: 2010-04-02
When I use randomize() and rand(), I get a sequence of random numbers in the range I need. However, I need to generate about a 1000 DIFFERENT sequences of random numbers in the given range. About 500 or so runs result in 500 same sequences since randomize() uses the system clock as a seed and 500 runs take less than a second to execute. In other words, since my program runs faster than the seed (clock seconds) can change, I get a lot of same sequences of random numbers. I tried slowing down the program by inserting loops but then it runs too slow. Is there anyway to get a 1000 different sequences?
0
Comment
Question by:mrmind3
8 Comments
 
LVL 22

Expert Comment

by:nietod
Comment Utility
On a windows computer you could use GetTickCount as a seed.

Are you seeding the randome number more than once per run of the program?  it sounds like you are.  There is no need.  Just seed 1 time, when the program starts and you won't get any repeats.
0
 

Author Comment

by:mrmind3
Comment Utility
But I do need to seed several times. I need to get  about a 1000 DIFFERENT sequences of random numbers not just one sequence.
0
 
LVL 1

Expert Comment

by:aperdon
Comment Utility
You could XOR all the generated random numbers, and use this as the next seed.
And perform some bit-swapping, or whatever, depending if the number is odd or even or so. This will for sure make 1000 different random sequences.
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
randomize() once
then get 1000 different sequences of rand()
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:aperdon
Comment Utility
This is what nietod also proposed, but mrmind3 wants to be able to start every sequence with a new seed.
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
Comment Utility
>> But I do need to seed several times.
>> I need to get  about a 1000 DIFFERENT
>> sequences of random
>> numbers not just one sequence.
what is?

 2 5 2 1 7 9 3 4

Is that a sequence of 8 random numbers?  Arre you sure it is not two sequences of 4 random numbers?  Perhaps it is 4 sequences of 2 random numbers

Just seed once, then generate the random numbers.  Where a sequence ends and another begins is arbitrary.  That is, it is up to you.  you don't have to use randomize() to start each sequence, just to start the process.
0
 
LVL 1

Expert Comment

by:aperdon
Comment Utility
I agree, but the second sequence of 4 numbers is affected by the first sequence, coz the rand() function is implemented in the way it has memory over the last generated numbers.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
If you want to be technical about it the numbers aren't random in either case.  But in either case the numbers will be evenly disrtibuted over the integer range and will display any easily detectable pattern.  So there is no difference in either case.  They are equally "random"
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

743 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

15 Experts available now in Live!

Get 1:1 Help Now