1
$\begingroup$

Apologies if this is overly simple but I wasn't able to find an answer online.

Question

Say I have a function defined as follows (and not two separate instances of random numbers),
f[x_,y_]:=x y

How can I input a set of 2 dimension random numbers into this function. Note that I want to generate a 2 dimension random number as follows,

RandomReal[{min, max}, {n, 2}]]

The problem is that RandomReal generates a list of lists as such

{{x_1,y_1},{x_2,y_3},...{x_n,y_n}}

And I cannot input this into the function. I also wanted to repeat this a bunch of times with a Table.

This is what I tried which obviously doesn't work,

Table[f[RandomReal[{min, max}, {n, 2}]]],{n,1,100}]

Thanks for any and all help!

$\endgroup$
3
  • 1
    $\begingroup$ There's actually a shorthand syntax for this! you're looking for Table[f @@@ RandomReal[{min, max}, {n0, 2}], {n,1,100}], I think. in general f @@@ { {a,b,c, ... }, {d,e,f, ...}, ...} is {f[a,b,c, ...], f[d,e,f, ...], ...}. (assuming I'm interpreting what you want correctly, ofc) $\endgroup$
    – thorimur
    Jul 10, 2021 at 8:33
  • 1
    $\begingroup$ Oh yes! That does work, thanks a lot. $\endgroup$
    – Boris
    Jul 10, 2021 at 13:02
  • $\begingroup$ You might also look into defining your function as Listable; however, thorimur's recommendation seems to be a more directly applied suggestion. $\endgroup$ Jul 11, 2021 at 15:02

0

Browse other questions tagged or ask your own question.