Re: Create random binary images
- To: mathgroup at smc.vnet.net
- Subject: [mg83669] Re: Create random binary images
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Wed, 28 Nov 2007 05:25:28 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <figtob$f90$1@smc.vnet.net>
Tara.Ann.Lorenz at gmail.com wrote:
> I am trying to create several random binary images of 30x30. I want
> the outputs to be 1's and 0's, with 5% of the outputs being 1's. Any
> ideas on how to code this in Mathematica?
One possible way is to use *RandomChoice* with a list of weights
associated to your values. For instance,
data = RandomChoice[{0.95, 0.05} -> {0, 1}, {30, 30}];
ArrayPlot[data]
Regards,
--
Jean-Marc