swarm-modeling
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Randomly initializing a N-element vector


From: Stephen C. Upton
Subject: Re: Randomly initializing a N-element vector
Date: Fri, 08 Oct 1999 14:30:14 -0600

At 12:53 PM 10/8/1999 -0700, jason alexander wrote:
I need to randomly initialize a N-element vector such that

 (a) every element is between 0 and 1
 (b) the sum of all elements is 1


Brute force:
1.  Set x = 0, cumulative sum
2.  Randomly generate number, r,  between x and 1
3.  Add r to x
4.  Repeat steps 2 and 3, N times
5.  Randomly mix resulting vector

hope this helps
upton








*** * **** * ***** ********* ** ****** ***** *** ***** ********
Stephen C. Upton  TSA-5, MS F602  Z119895                       
(505) 667-9435 Voice                    (505) 665-2017 Fax                      
address@hidden
********* ******* ********* *** ** *** ******** **** ****** **
"As far as the laws of mathematics refer to reality, they are not
certain, and as far as they are certain, they do not refer to reality"
Albert Einstein


                 ==================================
  Swarm-Modelling is for discussion of Simulation and Modelling techniques
  esp. using Swarm.  For list administration needs (esp. [un]subscribing),
  please send a message to <address@hidden> with "help" in the
  body of the message.
                 ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]