Page 1 of 1

random function

Posted: Fri Mar 21, 2008 5:53 am
by Guigui
Hi, I'm gonna try CF 2.2 beta. I was looking at the expressions page. At your purposal, I Let you know that I believe a random function would be nice:

and may look like this:
random(x, y) (or rand(x, y) or ran(x, y))
and returns a random floating-point number between x(the minimum) and y(the maximum)

also random(y) would mean random(0, y)
and random() would mean random(0, 1)

What do you think of that?
8^)

Posted: Fri Mar 21, 2008 9:06 am
by MtnViewJohn
It would be very easy to add a random function. But it would be kind of limited. The expressions are evaluated "at compile time". So you would get a random number, but it would be the same random number every time that particular rule is invoked.

We plan to have real random numbers in CF 3.0. A virtual machine will run each rule as if it was a little program. Expressions that depend on rule parameters or the random function would be re-evaluated on every invocation of a rule.

We deliberately left random functions out of CF 2.2 to eliminate confusion about limited CF2.2 behavior vs. complete CF 3.0 behavior. If you think that the CF 2.2 random function is still useful then I can add it. But I would call it something like const_random to make the random-but-constant nature of the function explicit.

Posted: Mon Mar 24, 2008 9:51 am
by Guigui
No, you're right, a const_random function seems to be useless (and there's still a lot of things to explore in CF2.2).