Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added RNG files #110

Merged
merged 2 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/rng.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "rng.c"
#include <stdlib.h>

int rng_rand(int max){
max++;
int limit = RAND_MAX - (RAND_MAX % max),r;
while((r = rand()) >= limit);
return r % max;
Apoorv-Gaurav-Agarwal marked this conversation as resolved.
Show resolved Hide resolved
}

int rng_roll(int droprate){
int r = rng_rand(droprate);
return (r==0)?1:0 ;
}
8 changes: 8 additions & 0 deletions src/rng.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef RNG_H
#define RNG_H

//Constants for probabilities

int rng_rand(int max); //returns a random number in the range [0, max]
int rng_roll(int droprate); //returns 1 with probability 1/droprate, else 0
#endif