This question is an extension if one I asked earlier today. Basically, I am trying to write an array comprehension in Julia that calls a function f(x) whose output is a random number. When a random number less than 0.5 is reached, I want it to kill the function. I was able to write the following code:
X=[f(i) for i in 1:1:100 if (j=f(i) ;j < 0.5 ? false: j>0.5)]
The problem with this is that this calls two separate instances of f(x), and because f(x) is random every time, the above won't kill the for loop at the correct instance. I tried
X=[J=f(i) for i in 1:1:100 if (J < 0.5 ? false: J>0.5)]
As an attempt to save that particular random number, but then it tells me J is not defined. Is there any way to save this particular random number to perform my array comprehension?
Aucun commentaire:
Enregistrer un commentaire