Re: lattice definition: help
- To: mathgroup@smc.vnet.net
- Subject: [mg11194] Re: [mg11186] lattice definition: help
- From: hwalker@gvtc.com (Hugh Walker)
- Date: Mon, 2 Mar 1998 23:10:49 -0500
Christofer Edling <cedling@sociology.su.se> asks: > 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). > Exploit the fact that the built-in function Random[] profuces a random real number z, 0 < z < 1. This function gives one solution to the problem posed. randArray[n_][{a_,b_,c_}]:= Module[{z}, Table[z=Random[]; If[z<0.3,a,If[z>0.8,b,c] ],{n},{n}] ] Cheers! Hugh Walker Gnarly Oaks