Jump to content

Recommended Posts

Okay im trying to write a program that creates a random number (1,52) and then determines what the card is.

 

for instance

 

1 = 2 of spades

2 = 2 of clubs

3 = 2 of diamonds

4 = 2 of hearts

 

 

I know that if the cards even, its either clubs or hearts. odd, spades or diamonds.

Is there way of determining if an even is club or heart? odd, spade or diamond?

 

 

Link to comment
https://forums.phpfreaks.com/topic/143402-deck-of-cards/
Share on other sites

Sorry must have worded by question wrong, I know how to determine if the number is even or odd.

 

Maybe it will help if I give an example:

 

Let's say rand(1,52) outputs 12   

 


<?php
$card = rand(1,52); 

if ( ( $card % 2 ) == 0 ) { 

//card is either Clubs, or Hearts

} else { 

//card is either Spades or Diamonds

} 

?>

 

This would only tell us that 12 is a club OR a heart.. I'm wondering after I figure this out, How would I go about finding out if 12 is a club OR if 12 is  a heart.

Link to comment
https://forums.phpfreaks.com/topic/143402-deck-of-cards/#findComment-752198
Share on other sites

I'm assuming that your (1,52) is a complete sets of card.

 

I would usually do a pre-defined sets of cards in an array.

 

So, let's say

1-13 = Spades

14-26 = Hearts

27-39 = Clubs

40-52 = Diamonds

 

Then check the number of the cards against these array of cards.

 

It's just an opinion.

 

Hope this help

 

Regards,

LPM

Link to comment
https://forums.phpfreaks.com/topic/143402-deck-of-cards/#findComment-752200
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.