Re: lattice definition: help
- To: mathgroup@smc.vnet.net
- Subject: [mg11200] Re: lattice definition: help
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Mon, 2 Mar 1998 23:10:54 -0500
- References: <6d0ch7$2no@smc.vnet.net>
Christofer Edling wrote:
> I wish to generate an n*n lattice with the following characteristics:
>
> 1. Each cell in the lattice can be in one out of three possible states,
> i.e. A,B,C.
> 2. The distribution of states across the whole lattice is defined by
> user input, i.e. 30% A's, 20% B's, 50% C's. 3. Given the defined
> distribution, each cell in the lattice should be randomly assigned a
> state (A,B or C).
Christopher:
lattice[{a_,b_,c_},n_]:=
With[{ca=a/100//N,cb =(a+b)/100//N},
Table[
Switch[ Random[],
_?(# < ca &), A,
_?(# < cb &), B,
_, C
],
{n},{n}
]
]
Of course, C is redundant information that could be left out. --
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642