Last active
December 27, 2017 06:51
-
-
Save themanyone/5e7d2e8df4b842092bfa8264992e6228 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//testing the gist | |
/* random.c | |
* | |
* Copyright (C) 2012-2018 by Henry Kroll III, www.thenerdshow.com | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
#include <stdio.h> | |
#include <stdarg.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <math.h> | |
#include <sys/time.h> | |
#define _STR(a) #a | |
#define STR(a) _STR(a) | |
#define LET(a) if (!(a)){ \ | |
perror(__FILE__":"STR(__LINE__));exit(1);} | |
#define FREE(a) free(a);a=NULL; | |
int runs=400, ceiling=56000.0; | |
double goal=.1, mult=1.147, startbet=.007, minbet=.7, tax=.0005, maxbet=500000, biggestloser=0; | |
//~ randinit | |
void randinit() { | |
struct timeval tv; /* seed srand() */ | |
gettimeofday (&tv,0); /* with something... */ | |
srand ((unsigned int)tv.tv_usec); | |
} | |
double getrand(double low, double high) { | |
return high*(rand()/(RAND_MAX+1.0))+low; | |
} | |
//{ main | |
int main (int argc, char **argv) { | |
int roll, j, win=0, losses=0; | |
double grand=0.0,take=0.0, bet=startbet; | |
randinit (); | |
for (j=0;j<runs;j++) { | |
while (take<0.0999&&take>=-999.0) { | |
roll=getrand (0.0,65535.0); | |
if (roll<=ceiling) { | |
take+=bet*(mult-1); | |
win=1; | |
} | |
else { | |
take-=bet; | |
win=0; | |
} | |
take-=tax; | |
if (runs<5||take>1.0) { | |
printf ("%5s %-4.3f, take %.4f\n",win?"won":"lost", bet, take); | |
} | |
//~ bet=getrand(minbet,maxbet) | |
bet=(fabs(take)+tax+goal)/(mult-1.0); | |
if (bet<minbet||win) bet=minbet; | |
if (bet>maxbet) bet=maxbet; | |
} | |
if (runs<5) printf ("ending take: %.4f\n",take); | |
if (take<0) { | |
losses++; | |
if (biggestloser>take) biggestloser=take; | |
} | |
grand+=take; | |
take=0.0; | |
bet=startbet; | |
} | |
printf ("total: %.4f avg: %.4f loss%%: %.2f most: %.4f\n",grand,grand/runs, (float)losses/(float)runs*100.0,biggestloser); | |
return 0; | |
} | |
//} main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment