Re: Create random binary images

*To*: mathgroup at smc.vnet.net*Subject*: [mg83678] Re: Create random binary images*From*: "Dana DeLouis" <dana.del at gmail.com>*Date*: Wed, 28 Nov 2007 05:30:41 -0500 (EST)

> 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? Hi. Here's one of many ways. This is Mathematica 6.0 size = 30*30; ones = Table[1, {Round[size*0.05]}]; zeros = Table[0, {size - Length[ones]}]; data = RandomSample[Join[zeros, ones]]; data = Partition[data, Sqrt[size]]; MyColors = ColorRules -> {0 -> Black, 1 -> Red}; ArrayPlot[data, MyColors] HTH Dana DeLouis