# Assiging random values to an array of variables [closed]

I want to create a number of variables and assign random values to them. This is possible in Python using a single line of command.

To be more specific say I want to create 10 variables whose value will be $[0.1,1]$ randomly. Instead of declaring every variable individually and then assigning values to them, is there any easier way to do this in Mathematica?

• Evaluate @ Array[x, 10] = RandomReal[1, 10] doesn't float your boat? – J. M.'s discontentment Aug 20 '15 at 20:40
• @J. M. No, but it bloat my goat – Dr. belisarius Aug 20 '15 at 20:50
• – Sjoerd C. de Vries Aug 20 '15 at 20:52
• @bel No, gloat loathing. – Sjoerd C. de Vries Aug 20 '15 at 20:54
• Wonders why it is necessary that these random values be assigned to individual variables and not concatenated in a list? – image_doctor Aug 20 '15 at 23:43

### Edit

Here is a Mathematica one-liner, courtesy of ciao, that does what you ask for:

SeedRandom[42];
Array[(x[#] = RandomReal[1]) &, 10];

Definition @ x

x[1] = 0.425905
x[2] = 0.391023
x[3] = 0.347069
x[4] = 0.453741
x[5] = 0.555963
x[6] = 0.289169
x[7] = 0.296848
x[8] = 0.206408
x[9] = 0.32517
x[10] = 0.973325


And here is another one, producing non-indexed variables.

SeedRandom[42];
MapThread[Set, {Symbol["x" <> #] & /@ IntegerString[Range[10]], RandomReal[1, 10]}];

List @@ OwnValues /@ Hold[x1, x2, x3, x4, x5, x6, x7, x8, x9, x10]

{{HoldPattern[x1] :> 0.425905}, {HoldPattern[x2] :> 0.391023},
{HoldPattern[x3] :> 0.347069}, {HoldPattern[x4] :> 0.453741},
{HoldPattern[x5] :> 0.555963}, {HoldPattern[x6] :> 0.289169},
{HoldPattern[x7] :> 0.296848}, {HoldPattern[x8] :> 0.206408},
{HoldPattern[x9] :> 0.32517}, {HoldPattern[x10] :> 0.973325}}

• Why not just Array[(x[#] = RandomReal[1]) &, 10] for the first? – ciao Aug 21 '15 at 0:32
• @ciao. Because I didn't think of that. – m_goldberg Aug 21 '15 at 0:35
• @m_goldberg, thanks for such elaborated answer. – jhon_wick Aug 21 '15 at 2:15