Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

Happy Holidays from the GTANet team!

dice [C]


Svip
 Share

Recommended Posts

I have written an application in C (which sources you will see in the bottom of this post). It simply rolls a N eyed dice a number of times, however it gives you a bit of features, and I hope to add more soon.

 

However, this applications may not work under Windows (unless using the prompt), since it works like another UNIX command (but I have not worked with DOS commands that much to know their nature).

 

At default, no 'input' is required, however it can be given, or as the help file reads:

 

 

[email protected]:~/prog$ dice helpdice version 1.0Usage:       dice [--force-row] [number of rolls [sides on dice] ]       dice [help|-h]--force-row       Use to display the row of the rollings for reference,       normally this information is not displayed.Standard values:Rolls: 1000, Eyes: 6

 

 

Of cause help|-h displays that help and terminates the application. As you can read there are standard values; it will roll 1000 times and use a six eyed dice on default.

 

Example:

 

[email protected]:~/prog$ diceRolling 6 eyed dice; 1000 times... Done!Number of eyes table:1       : 1722       : 1713       : 1694       : 1695       : 1436       : 176Logical Average: 166.666672

 

 

The logical average is a float variable calculated from rolls/eyes. The results are always different (not yet have I encounted alike results).

 

But the rolls and eyes can easily be changed.

 

Example:

 

[email protected]:~/prog$ dice 525 13Rolling 13 eyed dice; 525 times... Done!Number of eyes table:1       : 442       : 433       : 404       : 385       : 516       : 347       : 408       : 469       : 4710      : 2811      : 3912      : 3213      : 43Logical Average: 40.384617

 

 

In case you want to see the original row the rolls was returned to generate the final result, you can use --force-row in front of the 'rollings' and 'eyes' in the command (of course those two are not required when using --force-row). --force-row will display the information that is hidden on default cause it can be very long.

 

Example:

 

[email protected]:~/prog$ dice --force-row 200 3Rolling 3 eyed dice; 200 times...--force-row is turned on, displaying all the results of each roll as they come.2 3 3 3 2 1 3 1 3 3 3 1 2 2 2 1 2 2 2 1 3 3 1 3 2 2 1 3 2 3 1 3 3 3 3 1 1 2 1 32 1 3 3 3 2 1 1 1 3 2 3 3 2 3 1 2 3 2 3 3 2 2 3 2 2 3 1 1 2 3 2 3 1 2 2 2 3 3 23 1 2 2 1 2 3 2 2 1 1 2 3 3 1 2 1 1 2 1 3 2 2 2 2 1 1 1 1 1 3 3 2 3 1 2 2 3 3 32 1 2 1 3 3 3 3 3 1 1 3 1 3 1 2 1 2 3 1 2 3 3 1 3 1 2 1 1 3 3 2 3 2 3 3 2 2 3 21 2 2 1 2 3 3 2 2 3 3 1 3 3 2 3 3 2 3 2 1 3 3 1 3 3 3 1 2 1 3 3 3 2 1 1 2 3 3 1Done!Number of eyes table:1       : 552       : 653       : 80Logical Average: 66.666664

 

 

As you can see, the applications has some small nifty features, and now for the source code.

 

 

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#define TRUE 1//This definition is rather useless, I used it anyway.int get_rand(int j) {//This function simply returns a random value between 1 and j.//Though the rand() would return 0 to j-1, so I add 1 for this issue.       return rand()%j + 1;}int game(int g, int l, int row) {//This function does the game entirely.       int i,n; //i is used for counting, n is the random number from the function       long a[g]; //a is our array, which has g elements, g being the amount of eyes       float f, fg, fl; //float variables, it did not somehow work with f= l/g, so I made some floats up!       for(i=0;i<g;i++) //This is perhaps not required, but I am using it                        //just in case it is.               a[i] = 0;       srand(time(NULL)); //Make sure that the random returns different values                          //from run to run.       printf("Rolling %d eyed dice; %d times... ",g,l);       if(row==TRUE) //If --force-row is on, tell the user.               printf("\n--force-row is turned on, displaying all the results of each roll as they come.\n");       for(i=0;i<l;i++) {               n = get_rand(g); //Get the random value from the function above               if(row==TRUE) { //Show the user the roll if row is TRUE.                       printf("%d ",n);                       if(!((i+1) % 40))                               printf("\n");               }               a[(n-1)]++; //Add one to the element in the array (a).       }       if(row==TRUE) {printf("\n");}       printf("Done!\n"); //Tell the user we have done the "calculations".       printf("Number of eyes table:\n");       for(i=0;i<g;i++) //Print the table of results.               printf("%d\t: %d\n",(i+1),a[i]);       fl = l; fg = g;       f = fl/fg;       printf("Logical Average: %f\n",f); //A calculated average for reference.}int main(int argc, char *argv[]) {       //This is the main function, it just make sures the application       //goes in the right direction.       static char buffer[20];       int p;       p = 2; //p is 'like' a pointer, pointing at the 'word' in the input field.       if(argc >= p) //Check if user have inputted anything otherwise                       //we would get a segfault.               strcpy(buffer, argv[1]);       if((!strcmp(buffer, "help")) || (!strcmp(buffer, "-h")))       { //Print help if user have typed "help" or "-h".               printf("dice version 1.0\n\n");               printf("Usage:\n");               printf("\t%s [--force-row] [number of rolls [sides on dice] ]\n",argv[0]);               printf("\t%s [help|-h]\n",argv[0]);               printf("\n--force-row\n\tUse to display the row of the rollings for reference,\n\tnormally this information is not displayed.\n");               printf("\nStandard values:\n");               printf("Rolls: 1000, Eyes: 6\n");       }       else { //If the user haven't asked for help, get the values he have inputted.               int l,g,n;               if(!strcmp(buffer, "--force-row")) {                       n = TRUE;                       p++; //Since the first 'word' is already used, we need to check the correct line next time.               }               if(argc < p)                       l = 1000;               else {                       l = atoi(argv[(p-1)]); //Remember to make it a number from string, heh.                       p++;               }               if(argc < p)                       g = 6;               else {                       g = atoi(argv[(p-1)]); //Same as above.                       p++;               }               game(g,l,n); //Run the game function!       }}

 

 

I hope you enjoy, I got the idea in physic class when our teacher said something about getting a computer to calculate how a dice would roll a thousand times.

Link to comment
Share on other sites

Nice one svip, now just add some graphics and sell it to Microsoft wink.gif

Err...? what?*

 

Anyways, I am glad you liked it, hope more to think so as well.

 

*Seriously, I cannot see what was funny in that post, it was wrong in so many ways.

Link to comment
Share on other sites

I actually find this program quite interesting, however pointless it may seem, due to my inexplicable interest with probability.

 

Maybe you could add a Standard Deviation feature, showing the variation of the data from the average.

Link to comment
Share on other sites

<!-- nice app, i guess. rather simple, but neat.

 

(don't really see the point of the topic though) -->

Link to comment
Share on other sites

just another thug
Very cool, we had to do something like this, only I wrote it in Java. It wasn't as complex but it had the same idea.
user posted image
Link to comment
Share on other sites

  • 2 weeks later...

To make f=l/g work in one line without dummy variables, you have to typecast the integers as floats:

 

f = ((float)l)/((float)g); //This will give you a good floating point result with no truncation.

 

Edit: And what is it supposed to be, anyways? Number of rolls divided by number of sides? What's the point? Wouldn't it make more sense to compute the actual average roll and a statistically predicted one? Statistical average, by the way, will allways be (g+1)/2, regardles of l.

Edited by K^2

Prior to filing a bug against any of my code, please consider this response to common concerns.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.