Skip to content

Instantly share code, notes, and snippets.

@fliiiix
Last active December 16, 2015 11:58
Show Gist options
  • Select an option

  • Save fliiiix/5430854 to your computer and use it in GitHub Desktop.

Select an option

Save fliiiix/5430854 to your computer and use it in GitHub Desktop.
Do What The Fuck You Want To Public License
/*******************************************************************************
*
*
* Beschreibung: Diese Programm kann zufällige zahlen Generieren.
*
* Benötigte Libraries:
* - stdlib.h
* - stdio.h
* - time.h
*
* Do What the Fuck You Want to Public License
*******************************************************************************/
/*** Include Files ***********************************************************/
#include <stdlib.h> /* Funktionsbibliothek: Hilfsfunktionen */
#include <stdio.h> /* Funktionsbibliothek: Standard Ein- Ausgabe */
#include <time.h> /* Funktionsbibliothek: Bibliothek der Zeit*/
/*** Globale Deklarationen und Definitionen **********************************/
void getRandomSeed()
{
static char zufall;
if(zufall != 1)
{
/* inizialisierung random seed: */
srand ( time(NULL) );
zufall = 1;
}
}
int getRandom(int Min, int Max)
{
getRandomSeed();
return (rand() % (Max - Min +1) + Min);
}
double getRandomDouble(double Min, double Max)
{
getRandomSeed();
return Min + ((Max +1.0) * rand() / Max);
}
int main(void)
{
int i;
for(i=0; i<20; i++)
{
printf("Die loesung ist %d\n", getRandom(12,14));
}
for(i=0; i<20; i++)
{
printf("Die loesung ist %d\n", getRandomDouble(1.1,2.3));
printf("Die loesung ist %f\n", getRandomDouble(1.1,2.3));
}
system("PAUSE");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment