Inconsistent behaviour of random() and Random.N()

Inconsistent behaviour of random() and Random.N() - Messages

#1 Posted: 1/28/2020 8:04:24 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

I just came across a nasty difference between random(x) and Random.N(0,x) (the first being native SMath, the second from the Statistical Tools plugin).
If you store random(x) in a variable, the function is called each time the variable is used. If you do that with Random.N(), then a fixed value is stored at definition time, as if there was an internal eval() used.

If you want a fixed value when using random(), then you have to use eval().

The behavour of random() puzzled me when preparing an online worksheet , where I had to fall back to random().

Yet, when remembering that assignment is just storage of an expression with taking into account existing definitions but not doing any computation, then random() behaves consistent and Random.N() does not.

The worksheet would look better without eval() and I can't expect third party readers to understand why it is there.

ran.png
ran.sm (6 KiB) downloaded 29 time(s).
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 users liked this post
sergio 1/29/2020 6:36:00 AM
#2 Posted: 1/29/2020 8:58:01 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

The behavour of random() puzzled me when preparing an online worksheet , where I had to fall back to random().


Try this Martin, it may work in your SS 7251.
Cheers ... Jean

ran Otherwise.sm (23 KiB) downloaded 27 time(s).

  • New Posts New Posts
  • No New Posts No New Posts