[opensource] Random seed

Jim Dinan dinan at cse.ohio-state.edu
Tue Mar 20 00:35:18 EDT 2007


Hi Brian,

I think that line 592 might be the source of your bug:

----
if (sideDeck)
  oldPosition = random.nextInt(deckLength-16)+1;
----

It looks like decklength is already adjusted above so subtracting 16 may
be redundant.

A couple other pointers:

You should consider making a Deck class rather than storing everything
in a string array.  This class can contain the boolean "sideDeck" and
any other deck info.

You should also create a Card class that has fields for all of the card
data.

Once you have this Card class, you can store all of the cards in the
Deck class as a list of Card objects.  I'm a bit out of date on the Java
API so maybe someone else can suggest a better alternative, but I would
consider using a Vector<Card> (Vector of Cards) to store the deck.

Good luck,
 ~Jim.

BRIAN SWANEY wrote:
> I am working on a Java code that shuffles a deck of Yu-Gi-Oh cards (a rather complicated game; see https://www.upperdeckentertainment.com/yugioh/en/gameplay/rulebook/rulebook_v06_EN.pdf for details on the rules), and have mostly formatted the display of cards by now, but cannot shuffle the deck. I probably don't understand the random seed syntax.
> 
> My algorithm involves listing cards from 1 to 40, randomly selecting a card from that list, copying it in sequence onto a second list, then blanking out the previous card position to note that it was already taken. It seems that no matter what I enter as the seed, it doesn't go through all the cards and only repeats things that it already took (like 32 to 35 out of 40 cards). Can anyone with a bit of spare time and acceptance of newbies look it over and give me some (appreciated) advice?
> 
> PS - Sorry that the methods are not too organized...
> 
> -Brian Swaney
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Opensource mailing list
> Opensource at cse.ohio-state.edu
> http://mail.cse.ohio-state.edu/mailman/listinfo/opensource


-- 
James Dinan <dinan at cse.ohio-state.edu>

Graduate RA - Computer Science and Engineering
              The Ohio State University


More information about the Opensource mailing list