Re: Matrix question
- To: mathgroup at smc.vnet.net
- Subject: [mg60304] Re: [mg60287] Matrix question
- From: "David Park" <djmp at earthlink.net>
- Date: Sat, 10 Sep 2005 22:36:23 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Needs["DiscreteMath`Combinatorica`"]
randommatrix[n_, p_] :=
Module[{worklist, numones = Floor[p n^2]},
worklist = Join[Array[1 &, numones], Array[0 &, n^2 - numones]];
worklist = Part[worklist, Ordering[RandomPermutation[n^2]]];
Partition[worklist, n]]
randommatrix[4, 0.5] // MatrixForm
First I made an array of the required number of 1's join to the remainder
zeros. Then I made a random permutation of the list. Then I partitioned the
list into rows.
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: sandog [mailto:sandog at mail.gr]
To: mathgroup at smc.vnet.net
i want to create a NxN matrix with zeros but i want a percentage of the
matrix spots to be one at random spots any idea? cause i have no clue how to
do that.
Any help appreciated thx .