Using integer and modulus division, determine how a deck of 52 cards can be represented by randomly generating 52 number. Each number should have a numeric value and a suit (ex: 4 of clubs)
9 1268 Rabbit 12,516
Recognized Expert Moderator MVP
This isn't a code writing service, what have you tried so far?
I've been on this project for weeks and I can't figure out anything. The only thing I can think of is assigning a string to every number and making the random number not repeat itself, but that doesn't include any division.
Rabbit 12,516
Recognized Expert Moderator MVP
Here's a hint, if you integer divide a random number from 0-51 by 13 you get 0,1,2, or 3. 4 possible results for 4 possible suits. If you mod a random number from 0-51 by 4, you get a number from 0-12. 13 possible results for the 13 possible card ranks.
How do I make the numbers not repeat the same outcome?
Rabbit 12,516
Recognized Expert Moderator MVP
1) Generate a random number.
2) Check an array that stores the generated numbers to see if it's already in there.
3) If it's in there, go back to 1.
4) If it's not in there, put it in the array.
I got the card numbers and suits to work, but I still don't know how to use an array to make the numbers stop repeating.
Rabbit 12,516
Recognized Expert Moderator MVP
Each time you generated a card, you loop through the array to see if you already generated before hand.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: JC |
last post by:
I am very new to programming and learning on my own.
Why do I keep getting duplicate values using this code? I want to shuffle a
deck of 52 cards. The logic seems right to me.
Randomize
For...
|
by: Radith |
last post by:
Hi All,
I have got this task which I cant get my head around:
It asks how I would store information:
I just want to get an opinion from the group:
So here's the question:
"
You have been...
|
by: garyrowell |
last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received.
The program
This week you are going to write three...
|
by: Vneha |
last post by:
import java.util.*;
public class Deck {
public static int numSuits = 4;
public static int numRanks = 13;
public static int numCards = numSuits * numRanks;
private Card...
|
by: l1nuxxx |
last post by:
I have a file well call file.pl. It's a card sorting program. I need to create a lib fuction with part of the original file that shuffles the deck of cards. After it shuffles the first deck and deals...
| |
by: dr4g0nk1ng |
last post by:
i have this class that should create an array of cards
public class DeckOfCards{
public Card card;
public Card deck;
DeckOfCards() {
for (int s = 0; s < 3; s++)
|
by: blehhhhh |
last post by:
So I'm trying to work on this problem of deck of cards wherein I have a few classes along with a tester class. Everything else is done. I just need help with implementing the methods properly. Here's...
|
by: amestrada113 |
last post by:
public Deck()
{
cards=new Card;
String suits = {"spades", "hearts", "clubs", "diamonds"};
int values = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
for (int j=0; j<values.length;...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |