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

Inconsistent behaviour of random() and Random.N() - 消息

#1 已发布: 2020/1/28 20:04:24
Martin Kraska

Martin Kraska

1,362个赞,共2,276个帖子。

组: 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.47 KiB)已下载 1507 次。
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
1位用户喜欢此帖子
sergio 2020/1/29 06:36:00
#2 已发布: 2020/1/29 08:58:01
Jean Giraud

Jean Giraud

983个赞,共6,866个帖子。

组: 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.84 KiB)已下载 1483 次。

  • 有新帖
  • 无新帖