Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • $\begingroup$ why not simply ClearAll[chooseFun]; chooseFun=RandomChoice? $\endgroup$ Commented May 22, 2021 at 14:06
  • $\begingroup$ @kglr Honestly, I was not aware of that function. Does chooseFun[x] evaluate properly though, in particular if one of the options is a user defined function like Log[x+1] or x^2_x as opposed to a system one like Log or Sqrt? (I ask because I usually think about f[x_]:=x^2 as saying "take x^2 and replace x by whatever is given", but chooseFun=RandomChoice doesn't take an input which confuses me.) $\endgroup$ Commented May 22, 2021 at 14:12
  • $\begingroup$ you need to use it as chooseFunb[{Sqrt, Log}]@xx or as fa =chooseFunb[{Sqrt, Log}]; fa@x $\endgroup$ Commented May 22, 2021 at 14:15
  • $\begingroup$ alternatively, you can define choseFun as ClearAll[chooseFun]; chooseFun := RandomChoice[{Sqrt, Log}]; Then chooseFun[t] gives Sqrt[t] or Log[t] at each invocation. $\endgroup$ Commented May 22, 2021 at 14:20
  • $\begingroup$ @kglr Sorry I am not understanding stuff, and/or I have not explained my question well. First, why chooseFunb in the earlier comment (i.e. why is there a "b" there?). Second, with ClearAll[chooseFun] chooseFun := RandomChoice[{Sqrt, Log}];, chooseFun[t] would (potentially) switch from Sqrt to Log on different evaluations, wouldn't it? $\endgroup$ Commented May 22, 2021 at 14:24