Group Abstract Group Abstract

Message Boards Message Boards

1
|
485 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Difficulties with a stochastic variable

POSTED BY: David Vasholz
2 Replies

fivetries@Unevaluated@RandomReal[] also works, but I would use HoldFirst or HoldAll as Gianluca shows.

Note Attributes@Table includes HoldAll, which is why the argument RandomReal[] in Table[RandomReal[],5] is not evaluated first; instead, it is evaluated when Table[] is ready to evaluate it.

POSTED BY: Michael Rogers

Try giving the attribute HoldFirst:

SetAttributes[fivetries, HoldFirst]
fivetries[arg_] := Table[arg, 5]
fivetries@RandomReal[]

This way the RandomReal is evaluated last, after the Table.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard