Re: How to make a loop for this problem!

• To: mathgroup at smc.vnet.net
• Subject: [mg75382] Re: How to make a loop for this problem!
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Fri, 27 Apr 2007 05:27:38 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <f0pkt5\$28h\$1@smc.vnet.net>

```pskmaths at googlemail.com wrote:
> Hi all,
>
> This comand:
> A = Array[Random[Integer] &, {3, 3}]
> generates a 3x3 random matrix its terms between 0 and 1.
>
> I need to make a loop that geerates a finite number of matrices, let's
> say 512 and this loop check that non of the matrices is equal to
> another one (no repeated matrices)
>
> I can geerate thoses random, matrices with this command:
> Do[Print[Array[Random[Integer] &, {3, 3}]], {512}]
> but I may have two matrices that are equal and also as far as I know I
> cann't use the out put because of the command, Print.

Here is a functional approach to solve your problem. matArray contains
the whole set (512 elements) of 3 by 3 matrices made of entries either 0
or 1. Then, you can access any element of the list with one or more
indices, either fixed or randomly generated.

In[1]:=
matArray = (Partition[#1, 3] & ) /@ Tuples[{0, 1}, 9];

matArray[[15]]
matArray[[Table[Random[Integer, {1, 512}], {2}]]]

Out[2]=
{{0, 0, 0}, {0, 0, 1}, {1, 1, 0}}

Out[3]=
{{{0, 0, 0}, {1, 0, 1}, {1, 0, 1}},
{{0, 1, 1}, {0, 1, 1}, {1, 1, 1}}}

Regards,
Jean-Marc

```

• Prev by Date: Re: an expression with logs
• Next by Date: Re: Solving a differential equation numerically in Mathematica
• Previous by thread: Re: How to make a loop for this problem!
• Next by thread: Re: How to make a loop for this problem!