Skip to content

Instantly share code, notes, and snippets.

@oliverbooth
Last active January 4, 2016 05:59
Show Gist options
  • Select an option

  • Save oliverbooth/8578832 to your computer and use it in GitHub Desktop.

Select an option

Save oliverbooth/8578832 to your computer and use it in GitHub Desktop.
Ranged random numbers
#include <stdlib.h>
#include <time.h>
void initrand() {
srand((unsigned) time(NULL));
rand();
}
int rangerand(int max, int min) {
if(max < min) max = min;
if(min > max) min = max;
return rand() % max + min;
}
#ifndef RANGERAND_H
#define RANGERAND_H
void initrand();
int rangerand(int max, int min = 0);
#endif // !RANGERAND_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment