how to create a program that simulates the process of dealing cards from a 52-card deck by generating 1,000 random integers in the range 1-52 assuming the numbers 1-13 are clubs 14-26 are diamonds, 27-39 are hearts, and 40-52 are spades displaying number of times each suit occurred in the 1,000 deals using a top down modular approach and pseudocode

Member Avatar

This sounds like an assignment. I'm not sure that this would work as you could have something like 17,45,32,45 for the first 4 numbers. That obviously wouldn't be right (same card drawn 2nd and 4th draws).

Would you be looking to exhaust the 1-52 integers before starting on the next random order of 1-52?

Anyhow here's an idea.

1) Have an array (0-51) var cardCodes = [0,1,2,3,4,5...51];
2) Have an array of arrays (0-51, for suits, values) var [['C',1],['C',2]...['S',13]];
3) Need a shuffle routine, e.g. (Durstenfeld shuffle algorithm)
4) Write a loop to run the algo x number of times (20?) and append results to an existing array each time
5) Slice off the array at 1000 items.

When you come to display the results possibly as draw card routine, you use the integer drawn to get the suit and value from the array of arrays.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.