Jump to content
  • entries
    4,958
  • comments
    2,719
  • views
    1,809,967

No randomness


atari2600land

347 views

So I googled "random in C" (what I'm using for this stupid game.) and found a whole bunch of examples, but they all use the rand() function, and efforts to find the included h files were in vain. But I did do one thing (I think): Shortened the code a bit for the dealing. It looks like this:

    for (i=0; i<5 ; i++)    {    // my stupid random code.    carddifference=carddifference+3;    if (carddifference>51) carddifference=14;        Cardnumber[i]=cardtype+carddifference;    if (Cardnumber[i]>52) Cardnumber[i]=Cardnumber[i]-52;                    // show cards.    if (Cardnumber[i]<14) Suitnumber[i]=1;    if ((Cardnumber[i]>13) && (Cardnumber[i]<27)) Suitnumber[i]=2, Cardnumber[i]=Cardnumber[i]-13;    if ((Cardnumber[i]>26) && (Cardnumber[i]<40)) Suitnumber[i]=3, Cardnumber[i]=Cardnumber[i]-26;    if (Cardnumber[i]>39) Suitnumber[i]=4, Cardnumber[i]=Cardnumber[i]-39;        suit=Suitnumber[i];    cardtype=Cardnumber[i];    showcardforpoker1thru13();    cardx=cardx+7;    }


Carddifference is also added to when the player needs to input something (like holding cards, or dealing a new game.) This is because I heard that a good way to randomize numbers is base it on user input. But it's not in this case. Right away, the player sometimes gets 2 pair, or a flush. I DON'T WANT THAT TO HAPPEN. I may just give up on this completely because, as usual, computers enjoy it when I get angry, so they do their best to ensure it.

1 Comment


Recommended Comments

Are you using gccVB from 2010, based on gcc 2.95, or trying to use the obsoleted Virtual-E compiler by Alberto Covarrubias? I saw that gccVB has been recently updated to use even more modern versions of gcc, though the availability of random number generators lie in the libraries rather than the compiler itself. However it has very sparse documentation, so I couldn't conclude if it still doesn't support random numbers.

 

Still, if you implement a LFSR like the one DZ-Jay posted, or some other routine that produces a pseudo random number like the lagged Fibonacci explained by intvnut, you should be able to get decent random numbers, better than the routine you came up with yourself. Converting code from IntyBASIC to C should be nearly trivial for you.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...