MathGroup Archive 1998

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

Search the Archive

Re: lattice definition: help



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




  • Prev by Date: How draw 3D Arrows?
  • Next by Date: anyone help with this...
  • Prev by thread: Re: How draw 3D Arrows?
  • Next by thread: Re: lattice definition: help