1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/*
* 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 <stdlib.h>
#ifndef MACOSX
#include <math.h>
#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);
#if PD_MINOR_VERSION < 37
class_sethelpsymbol(randomF_class, gensym("randomF-help.pd"));
#endif
}
|