ok.  with N as x Q as Y

amend_z_ =: 2 : 0  NB. v is n or verb that will eval to n}
s=. v"_ y 
(u (s{y)) (s}) y 
: 
s=. v"_ y         NB. May change to x v"_ y
(x u (s{y)) (s}) y 
)


  20 (] ((+/@:]-~[)  + amend (?@#)    ]) [ ?@:# <.@+:@%~) 100
2 3 3 1 5 9 27 0 6 5 7 3 9 6 0 4 7 1 1 1

puts most elements within the range of 0 to 2*q%n

adjusts 1 random element such that sum is 100.  (above result (27) is unusual). 
 Also possible for 1 negative element.



----- Original Message -----
From: Devon McCormick <[email protected]>
To: J-programming forum <[email protected]>
Cc: 
Sent: Friday, May 8, 2015 12:55 PM
Subject: Re: [Jprogramming] Random distribution

Like this?
   V=. 3 6 3 7 7 4 7 0 10 5 4 1 5 5 8 5 7 3 2 8 [ 'N Q'=. 20 100
   (N,Q) -: (#,+/) V
1



On Fri, May 8, 2015 at 12:50 PM, 'Pascal Jasmin' via Programming <
[email protected]> wrote:

> You possibly means something other than
>
> N = #V
>
> ?
>
> Maybe show some valid vectors for small Q?
>
>
> ----- Original Message -----
> From: Dan Bron <[email protected]>
> To: [email protected]
> Cc:
> Sent: Friday, May 8, 2015 12:47 PM
> Subject: Re: [Jprogramming] Random distribution
>
> I think you've got a model in your head where Q=N; in that case, yes, your
> function should produce N#1 .  But N and Q are independent variables.
>
> -Dan
>
> ----- Original Message ---------------
>
> Subject: Re: [Jprogramming] Random distribution
>    From: "'Pascal Jasmin' via Programming" <[email protected]>
>    Date: Fri, 8 May 2015 16:27:33 +0000 (UTC)
>      To: "[email protected]" <[email protected]>
>
> For Q = 3,
>
> only 1 1 1 would match your criteria
>
> for Q = 4,
> 2 2 would not be N=#V
>
> 1 1 1 1 again appears to be the only match I see.
>
>
> ----- Original Message -----
> From: Dan Bron <[email protected]>
> To: [email protected]
> Cc:
> Sent: Friday, May 8, 2015 11:54 AM
> Subject: [Jprogramming] Random distribution
>
> I have a quantity Q and I want to divide it into a vector V of N
> randomly-sized chunks, such that N=#V and Q=+/V .
>
> Ideas?
>
> -Dan
>
>
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Devon McCormick, CFA

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to