From c8f3e3674f08bf56407e478c3160c4392196c118 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 30 Jul 2003 21:52:27 +0000 Subject: separated out all objects into individual files; created a few missing help files; moves all help files to new 0.37 help- standard; removed [reson~] and [abs~] since they are now maintained elsewhere; created Makefile for Linux and Darwin svn path=/trunk/externals/markex/; revision=806 --- randomF.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 randomF.c (limited to 'randomF.c') diff --git a/randomF.c b/randomF.c new file mode 100644 index 0000000..d7e4046 --- /dev/null +++ b/randomF.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 1997-1999 Mark Danks. + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. + */ + +#include "m_pd.h" +#include + +#ifndef MACOSX +#include +#endif + +#ifdef NT +int random(void) +{ + static int foo = 1489853723; + foo = foo * (int)435898247 + (int)9382842987; + return (foo & 0x7fffffff); +} +#endif + +/* -------------------------- randomF ------------------------------ */ + +/* instance structure */ + +static t_class *randomF_class; + +typedef struct _randomF +{ + t_object x_obj; + t_float x_range; + t_outlet *t_out1; /* the outlet */ +} t_randomF; + +static void *randomF_new(t_floatarg n) +{ + t_randomF *x = (t_randomF *)pd_new(randomF_class); + x->x_range = (float)n; + floatinlet_new(&x->x_obj, &x->x_range); + x->t_out1 = outlet_new(&x->x_obj, 0); + return (x); +} + +static void randomF_bang(t_randomF *x) +{ + double range = (x->x_range < 0 ? 0 : x->x_range); + double n = (double)range * (double)random() * (1. / 2147483648.); + if (n >= range) n = range - 1; + outlet_float(x->t_out1, (float)n); +} + +void randomF_setup(void) +{ + randomF_class = class_new(gensym("randomF"), (t_newmethod)randomF_new, 0, + sizeof(t_randomF), 0, A_DEFFLOAT, 0); + + class_addbang(randomF_class, (t_method)randomF_bang); + + class_sethelpsymbol(randomF_class, gensym("help-randomF")); +} -- cgit v1.2.1