mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 23:51:29 -07:00
Implemented text and clipping primitives in the frontend, and added
two new simple games `fifteen' and `sixteen'. [originally from svn r4173]
This commit is contained in:
25
misc.c
Normal file
25
misc.c
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* misc.c: Miscellaneous helpful functions.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "puzzles.h"
|
||||
|
||||
int rand_upto(int limit)
|
||||
{
|
||||
unsigned long divisor = RAND_MAX / (unsigned)limit;
|
||||
unsigned long max = divisor * (unsigned)limit;
|
||||
unsigned long n;
|
||||
|
||||
assert(limit > 0);
|
||||
|
||||
do {
|
||||
n = rand();
|
||||
} while (n >= max);
|
||||
|
||||
n /= divisor;
|
||||
|
||||
return (int)n;
|
||||
}
|
Reference in New Issue
Block a user