2
$\begingroup$

I want to get n random numbers (e.g $n=16$)(whole numbers) between $1$ to $5$ (including both) so that average is $x$.

$x$ can be any value between $(1, \ 1.5,\ 2, \ 2.5,\ 3,\ 3.5,\ 4,\ 4.5,\ 5)$.

I am using PHP.

e.g. Suppose I have average $x= 3$.

Then required $16$ whole numbers between $1$ to $5$ (including both), like $(1,\ 5,\ 3,\ 3,\ 3,\ 3,\ 2,\ 4,\ 2,\ 4,\ 1,\ 5,\ 1,\ 5,\ 3,\ 3)$

Update:

if $x=3.5$ means average of $16$ numbers should be between $3.5$ to $4$.
and if $x=4$ means average of $16$ numbers should be between $4$ to $4.5$
and if $x=5$ means all numbers are $5$

  • 0
    If x is an integer, try: x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x. Otherwise, y=x-.5 is an integer then try: y, y, y, y, y, y, y, y, y+1, y+1, y+1, y+1, y+1, y+1, y+1, y+1.2012-03-30
  • 0
    I don't want all the numbers x. I want random numbers.2012-03-30
  • 0
    `x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x` **IS** a random sample. You will not find any other sample whose probability to occur would be greater.2012-03-30

4 Answers 4