aspose file tools*
The moose likes Beginning Java and the fly likes Regarding 'Random' numbers.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regarding Watch "Regarding New topic
Author

Regarding 'Random' numbers..

kannan vinayagam Duraiswamy
Ranch Hand

Joined: Jan 12, 2009
Posts: 52
Hi
i try to develop a small card game using java (just like 'hearts' in windows OS)
in the start of the game i need to give 'random' cards to each user.
how can i implement this ...any idea..


Kannan.DV
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
add all the cards to a collection (arraylist perhaps)
then use Collections.shuffle(..) and deal 'em out (from the bottom!)
kannan vinayagam Duraiswamy
Ranch Hand

Joined: Jan 12, 2009
Posts: 52
"deal 'em out (from the bottom!)" - are you mean to say that
iterate the list from the bottom after shuffle...
thanks for your response...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
I think Michael forgot 1st April was last week when he said "from the bottom"
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10246
    
    8

Kannan,

In card games (read "gambling") it is "illegal" to deal from the bottom of the deck. You are liable to get kicked out of the club, barred from all casinos in Las Vegas or get killed!

It was just a phrase which Michael used in jest. He did not literally mean the last element in the ArrayList

For more on bottom dealing check this out
http://en.wikipedia.org/wiki/Bottom_dealing

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
I think your explanation is easier to understand than mine, Maneesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding 'Random' numbers..