|
-
February 24th, 2009, 10:59 AM
#1
Multiple Random Sequences
My problem is that I want to be able to produce repeatable sequences of random numbers.
My simplified example of what I want to accomplish:
Poker Game: I want to be able to shuffle the deck & deal the cards to 10 players. play the hand/game then be able to repeat the game, but moving each player around the table. Therefore everyone gets to play everyone elses hand.
Now this seems obvious to just seed using a known number, then reseed it to produce the same sequence. But my problem is that while playing any given hand I may use rand() an arbitrary number of times, in between dealing the cards. therefore the next time I use rand() it may be at sequence index[30] or index[42], which will then produce different numbers.
Is there anyway using rand() or some other random library to be able to pick and choose different sequences to randomize. Like keep sequence A for shuffling Cards and sequence B for other random uses.
I know the idea can be done, as I have used it in the 3d modelling software Maya, using its MEL command syntax ( annoyingly I know it's even written in C++ ):
http://download.autodesk.com/us/maya...ands/rand.html
-
February 24th, 2009, 11:03 AM
#2
Re: Multiple Random Sequences
Use two or more random number generator function objects. Such facilities are available from TR1 and Boost, or you can implement say, Mersenne Twister yourself into your own random number generator class.
-
February 24th, 2009, 11:12 AM
#3
Re: Multiple Random Sequences
Why regenerate the numbers? Just create a vector or list. Initialize it with the cards. Call random_shuffle to generate a random sequence. Each time you deal, just start at a different point in the array or list and wrap around to the beginning when you reach the end, or if you use a list, just remove the head, make it the new tail, then redeal.
-
February 24th, 2009, 11:21 AM
#4
Re: Multiple Random Sequences
GCDEF: tht concept works, but then plan is to generally play a whole game possibly 100 hands, see who the winner is for the whole game. then repeat the game, and see who the winner is (hopefully the same player).
if i wanted to utilise the same randomized set of cards then redeal them each hand, i'd have to have 10 games running concurrently keeping track of all different chip counts, hand, opponent weight tables etc... not very efficient for something as simple as multiple number sequences?
-
February 24th, 2009, 11:29 AM
#5
Re: Multiple Random Sequences
 Originally Posted by purebuu
GCDEF: tht concept works, but then plan is to generally play a whole game possibly 100 hands, see who the winner is for the whole game. then repeat the game, and see who the winner is (hopefully the same player).
if i wanted to utilise the same randomized set of cards then redeal them each hand, i'd have to have 10 games running concurrently keeping track of all different chip counts, hand, opponent weight tables etc... not very efficient for something as simple as multiple number sequences?
That doesn't make sense to me. You say you need the same sequence of cards repeated. How is regenerating the random sequence any different from reusing the original sequence? Why not just store copies of the original sequences then?
-
February 24th, 2009, 12:20 PM
#6
Re: Multiple Random Sequences
i said in my simplified example: that i only need to reuse card sequences for a particular hand, but really i need a reuseable sequence for a whole game.
a whole game i'd like to repeat many times, modifying a few starting positions. I "could" store this sequence as i use it for game 1: then reuse it for game 2, game 3... and so on. but game 1 may be over in 10 hands, game 2 may go on for 100 hands: game 3 may last 50 hands.
Thats wasted copies of sequences I may never need. Its a possible solution, but i guess having a way to generate the same sequence over n over is just simpler to implement.
-
February 24th, 2009, 05:36 PM
#7
Re: Multiple Random Sequences
 Originally Posted by purebuu
My problem is that I want to be able to produce repeatable sequences of random numbers.
You get that by seeding the random generator.
A seed is a number and each seed will produce the exact same sequence of random numbers.
-
February 24th, 2009, 05:42 PM
#8
Re: Multiple Random Sequences
 Originally Posted by _uj
You get that by seeding the random generator.
A seed is a number and each seed will produce the exact same sequence of random numbers.
Exactly! This is why you typically see a random number generator seeded with the result from a call to 'time' (a different seed is used for every run). Just seed your generator with the same number every time.
Viggy
-
February 25th, 2009, 12:37 AM
#9
Re: Multiple Random Sequences
 Originally Posted by _uj
You get that by seeding the random generator.
 Originally Posted by MrViggy
Just seed your generator with the same number every time.
Eh, but purebuu stated that in the original post:
 Originally Posted by purebuu
Now this seems obvious to just seed using a known number, then reseed it to produce the same sequence.
The way I interpreted the original problem was that purebuu wanted multiple random sequences that could be repeated separately yet used simultaneously, and if so, using random number generator objects seems like the right approach since they can be seeded separately.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|