Xcode-iPhoneOS/Demos/src/common.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 13 Mar 2011 11:17:11 -0700
changeset 5483 ccec742c9b7d
parent 3277 20326ba2bda2
permissions -rw-r--r--
Removed unreferenced variable
slouken@3277
     1
/*
slouken@3277
     2
 *	common.c
slouken@3277
     3
 *	written by Holmes Futrell
slouken@3277
     4
 *	use however you want
slouken@3277
     5
 */
slouken@3277
     6
slouken@3277
     7
#include "common.h"
slouken@3277
     8
#include "SDL.h"
slouken@3277
     9
#include <stdlib.h>
slouken@3277
    10
slouken@3277
    11
/*
slouken@3277
    12
	Produces a random int x, min <= x <= max 
slouken@3277
    13
	following a uniform distribution
slouken@3277
    14
*/
slouken@3277
    15
int
slouken@3277
    16
randomInt(int min, int max)
slouken@3277
    17
{
slouken@3277
    18
    return min + rand() % (max - min + 1);
slouken@3277
    19
}
slouken@3277
    20
slouken@3277
    21
/*
slouken@3277
    22
	Produces a random float x, min <= x <= max 
slouken@3277
    23
	following a uniform distribution
slouken@3277
    24
 */
slouken@3277
    25
float
slouken@3277
    26
randomFloat(float min, float max)
slouken@3277
    27
{
slouken@3277
    28
    return rand() / (float) RAND_MAX *(max - min) + min;
slouken@3277
    29
}
slouken@3277
    30
slouken@3277
    31
void
slouken@3277
    32
fatalError(const char *string)
slouken@3277
    33
{
slouken@3277
    34
    printf("%s: %s\n", string, SDL_GetError());
slouken@3277
    35
    exit(1);
slouken@3277
    36
}