Results 1 to 7 of 7

Thread: [RESOLVED] Random Numbers

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    31

    [RESOLVED] Random Numbers

    I'm pulling my hair, I'm just creating a bunch of different little experiments and little fun projects right now. I've got a Deal or No Deal thing that's going very well. I'm trying to create some XML/PHP dealies. And my last one is the where I hit a snag. I'm trying to create a Black Jack game, but my random number generator doesn't seem to be working right. Here's my code: {it's completely unfinished and I only started creating it.}

    PHP Code:
    session_start();

    if(!isset(
    $_SESSION['suite'])){    
              
    $_SESSION['suite'] = array("Hearts""Diamonds""Clubs","Spades");
    }

    if(!isset(
    $_SESSION['number']))
    {    
              
    $_SESSION['number'] = array("Two""Three""Four""Five""Six""Seven""Eight""Nine""Ten",    "Jack""Queen""King""Ace");
    }

    if(!isset(
    $_SESSION['cards']))
    {    
              
    $_SESSION['cards'];
    }

    function 
    showCard()
    {
              
    $suite $_SESSION['suite'][rand(03)];
              
    $number $_SESSION['number'] [rand(012)];
              return 
    $number .' of '$suite;
    }

    function 
    addToCardsArray($card){    
              
    $_SESSION['cards'][] = $card;
    }

    echo 
    '<form action="mypage.php">';
    echo 
    showCard() .'<br>';
    echo 
    showCard();
    echo 
    '</form>'
    The reason I say it doesn't work is that everytime I refresh my page, it returns the same card. Every once in a while it changes, but that happens after a minute or so, so it's not helpful at all.
    Last edited by Ataru Moroboshi; Oct 15th, 2007 at 04:50 PM.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Random Numbers

    Indent your code, then we'll talk.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    31

    Re: Random Numbers

    Hopefully that's indented better.

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Random Numbers

    well for 1, this isnt doing anything:

    PHP Code:
    if(!isset($_SESSION['cards']))
    {    
              
    $_SESSION['cards'];

    or this:
    PHP Code:
    function addToCardsArray($card){    
              
    $_SESSION['cards'][] = $card;

    EDIT:
    I tested your code, and it works just fine...
    http://www.subsoft.net/vbf/card.php
    Last edited by dclamp; Oct 15th, 2007 at 04:36 PM.
    My usual boring signature: Something

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    31

    Re: Random Numbers

    Cards is going to be a Session variable that keeps which cards have been played, so if a card is on the list, then a function would get a new card.

  6. #6
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Random Numbers

    well the top one still doesnt do anything. and did you see my link?
    My usual boring signature: Something

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    31

    Re: Random Numbers

    Yep, I saw it. I added a submit button to the page. That should refresh the page when I press it. I'm going to see if that works.

    That function:
    Code:
    function addToCardsArray($card)
    {     
              $_SESSION['cards'][] = $card; 
    }
    is supposedly to take a value and add the value onto the SESSION array. So it goes from 0 values to 1 value and so on. At least that's what I'm hoping.

    Edit: The post and submit button work. It gets new values. Good idea, I was hoping that just simply refreshing the page would work, but apparently not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width