Here is my code example:
ConstantArray[RandomInteger[{1, 5}], 10]
However as my output I get something like
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3}
A more complex example:
test := Module[{a, b, c}, (a = RandomInteger[{1, 100}];
b = RandomInteger[{1, 100}]; c = RandomInteger[{1, 100}];
If[TrueQ[a < b] == True && TrueQ[b < c] == True, True, False])]
Which chooses 3 random integers a, b, and c and returns True if b is between a and c, False otherwise. However, plugging in
ConstantArray[test, 10]
just gives a list of 10 True's or 10 False's.
How can I construct a list for which a function like this is evaluated for every element in the list, rather than just evaluated once with that single output repeated? What function would work better than ConstantArray here?
RandomInteger[{1, 5}, 10]
would do. $\endgroup$ConstantArray
takes its first argument, evaluates it and copies the result into an array whose size is prescribed by the second argument. That's why the entries are not "random". $\endgroup$Table[test,10]
. $\endgroup$