Need suggestions for more randomness

This is a discussion on Need suggestions for more randomness within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm working on a blackjack program and of course I need a random card draw function. Now the problem ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    34

    Need suggestions for more randomness

    Hi, I'm working on a blackjack program and of course I need a random card draw function. Now the problem is I don't have one, it's I need to improve it
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <cmath>
    #include <ctime>
    #include <string>
    using namespace std;
    int a;
    int draw(int a);
    int main(){
        draw(c);
        cin.ignore();
    };
    int draw(int a) {
        int b, c, e;
        string d;
      srand(time(0));
      b = rand() % 52;
      c = b % 4;
      e = b % 12;
      switch (c){
             case 0:
                  d = "Hearts";
             case 1:
                  d = "Diamonds";
             case 2:
                  d = "Spades";
             case 3:
                  d = "Clubs";
                  }
      
      cout<< e << " of "<< d;
      
      return b;
    };
    The out put always has clubs as the suit. Any suggestions on how to improve the randomness?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Use breaks in your switch statement.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    34
    Heh heh that would help....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Suggestions?!
    By liljp617 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-20-2008, 11:12 AM
  2. Free Book Suggestions!
    By valaris in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-08-2008, 10:25 AM
  3. Hi, Suggestions on my program please..
    By Siggy in forum C++ Programming
    Replies: 44
    Last Post: 11-23-2004, 09:55 PM
  4. Math Book Suggestions
    By curlious in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-09-2003, 10:43 AM
  5. Need Suggestions
    By Drew in forum C++ Programming
    Replies: 3
    Last Post: 09-18-2003, 05:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21