# Loop calculations with random numbers

Given a function f

f=f[x,y,z]


I would like to compute f for different random values of x,y and z greater than 0

x:=RandomReal[n]; y:=RandomReal[n]; z:=RandomReal[n]


say 20 times, and show them as a set, each value of x,y,z and f, I mean something like {x,y,z,f}. I tried

x:=RandomReal[n]; y:=RandomReal[n]; z:=RandomReal[n]
Do[Print[f[x,y,z]],20]


but it didnt work. As I said, each values of x,y and z must be different, in general.

• You didn't specify a value for n – Simon Woods Sep 25 '15 at 20:44
• My mistake, let us say n=10. – Patrick El Pollo Sep 25 '15 at 20:52

## 2 Answers

ClearAll[f]
n = 5
data = RandomReal[n, {20, 3}]
Map[{Sequence @@ #, f @@ #} &, data]

• It works, thank you. – Patrick El Pollo Sep 25 '15 at 22:44

Other ways:

f[x_, y_, z_] := z + y + z
r = RandomReal[{0, 1}, {10, 3}];

r /. a : {_, _, _} :> Join[a, {f @@ a}]
r /. a : {_, _, _} :> Append[a, f @@ a]
MapThread[Append, {r, f @@@ r}]

• It works nicely too. Thanks – Patrick El Pollo Sep 25 '15 at 22:44
• OK, that last one is pretty cool. – Alan Sep 26 '15 at 1:57