3

I want to define a function which returns a random number:

gnuplot> rnd() = int(rand(0)*2**24)
         ^
         invalid command

I need add a parameter x to stop the error message:

gnuplot> rnd(x) = int(rand(0)*2**24)

Is it possible to define a function without parameters?

1 Answer 1

3

I don't think that is possible (look at the syntax for functions in help user-defined). As far as I can tell -- using rand is the only time when this is useful -- In all other cases your "function" would just evaluate to a constant. I'm guessing the gnuplot devs just haven't thought of this (interesting) corner case, or they didn't think it useful enough to implement.

I hope that I'm wrong about this and somebody else comes along and proves it, but I don't think I am. I think the easiest workaround it to just pass a parameter as you've already mentioned. If you really don't like that, you could use a macro:

set macro
rnd="(int(rand(0)*2**24))"
print 5+@rnd
Sign up to request clarification or add additional context in comments.

1 Comment

You said "rand is the only time when this is useful". I often write functions with a dummy parameter. These will eventually invoke something like column(42).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.