I have defined the following function:
randvec[mag_]:= mag Normalize[Table[RandomReal[], {j, 1, 4}]]
I would like to format the numbers in the list so that they are 4 d.p. Trying the following:
randvec[mag_] := NumberForm[mag Normalize[Table[RandomReal[], {j, 1, modes}]], 4]
casts each entry as a string. What is the appropriate way to format the list without changing the type of the entries?
randvec[mag_] := N@Round[mag Normalize[Table[RandomReal[], {j, 1, 4}]], 1*^-4]? – MarcoB Jan 14 '21 at 18:30RandomReal[{0, 1}, modes]will do the same as your table, but more efficiently. I also wonder if this question dealing with the generation of random vectors with a specified magnitude might be relevant to you: Vectors with a certain magnitude in Mathematica. – MarcoB Jan 14 '21 at 18:42