random function

Here you can discuss and share functionality improvements and helper programs to make Context Free better.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
User avatar
Guigui
Posts: 50
Joined: Sat Aug 05, 2006 5:28 pm
Location: Annecy, France

random function

Post 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^)
8^)

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post 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.

User avatar
Guigui
Posts: 50
Joined: Sat Aug 05, 2006 5:28 pm
Location: Annecy, France

Post 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).
8^)

Post Reply