MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: lattice definition: help



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




  • Prev by Date: Problem plotting lists of 3d graphics objects
  • Next by Date: Using Nodal
  • Prev by thread: Re: lattice definition: help
  • Next by thread: Re: lattice definition: help