Skip to content

Instantly share code, notes, and snippets.

@mizzy
Created July 28, 2017 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizzy/8e6e68c308fda235de9436fc5475f277 to your computer and use it in GitHub Desktop.
Save mizzy/8e6e68c308fda235de9436fc5475f277 to your computer and use it in GitHub Desktop.
#include "mruby.h"
#include <stdlib.h>
static mrb_value mrb_rand(mrb_state *mrb, mrb_value recv)
{
int n = rand();
return mrb_fixnum_value(n);
}
static mrb_value mrb_srand(mrb_state *mrb, mrb_value recv)
{
int n;
mrb_get_args(mrb, "i", &n);
srand(n);
return mrb_nil_value();
}
void mrb_mruby_rand_gem_init(mrb_state *mrb)
{
struct RClass *r = mrb_define_module(mrb, "Random");
mrb_define_module_function(mrb, r, "rand", mrb_rand, MRB_ARGS_NONE());
mrb_define_module_function(mrb, r, "srand", mrb_srand, MRB_ARGS_REQ(1));
}
void mrb_mruby_rand_gem_final(mrb_state *mrb)
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment