Wierd problem

This is a discussion on Wierd problem within the C++ Programming forums, part of the General Programming Boards category; Quzah: I think his problem was that when he wants to randomly generate a card to deal to a player, ...

  1. #16
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Quzah:
    I think his problem was that when he wants to randomly generate a card to deal to a player, it might sometimes generate the same card.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  2. #17
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That's why I said if you start with an array numbered 0 through 52 and shuffle it ...
    Code:
    for( x = 0; x < 100000; x++ )
    {
        int one, two, bucklemyshoe;
    
        one = rand() % 52;
        two = rand() % 52;
    
        bucklemyshoe = deck[ one ];
        deck[ one ] = deck[ two ];
        deck[ two ] = bucklemyshoe;
    }
    You know, something like that...

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    In C++, you could simply use std::random_shuffle.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM

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