It's not "random" if the average is anything but (* (+ min max) 0.5)
Name:
Anonymous2010-09-13 8:47
>>2
For length->oo in a discrete countable domain (integers for example), that is true, but irrelevant.
If you want another definition for random:
If I run the code enough times, I'll get all such possible sequences, and not any more.
Name:
Anonymous2010-09-13 9:07
span = 2 * (max - average)
min = max - span
[min + rand(span) for _ in length]
sewdo-code
Name:
Anonymous2010-09-13 9:20
>>4
Try it, won't work. Assuming rand(span) returns anything from 0 to span, it's possible that all rand's return 0.
Therefore your sequence is made of min's only and its average is min and not average, but min is equal max - 2average, so they're not necessarily equal
>>7
Protip: the problem is NP-hard because OP is forcing you to use the same random generator you use for the numbers with its properties in the rest of your program. It's a form of a vicious cycle. If you assume two rands, pseudorand() and truerand(), then it's easily solvable.
getAvgRand len avg max = fix (\f (x:xs) -> x >>= maybe (f xs) return) $ map (\x -> sequence x >>= \y -> if (fromIntegral $ sum y) / fromIntegral len == avg then return (Just y) else return Nothing) (repeat $ take len $ repeat $ randomRIO (0, max))
Name:
Anonymous2010-09-13 10:51
plonk plonk
Name:
Anonymous2010-09-13 10:52
plonk plonk
Name:
Anonymous2010-09-13 12:38
>>1
Wow, it's a good challenge for a change, thank you OP.
Also, shows how many morons there are on [spoiler]\gorp[/spoiler].
Interesting fact: it becomes almost obvious (as in, "I've done this before") as soon as you replace "average" (which is floating-point and therefore sucks) with "sum". Then all that you need to do is to enumerate all such sequences (i.e. get the total number and construct the function index -> sequence, see generation of n-th transposition), then select a random number in that range.
Obviously, as a Systems Architect I'm not going to write the code. If a dimwit like >>10,8 can understand my superior design then he is welcome to implement it. Though I highly doubt he would be up to the task, he seems to have been exposed to haskal for long enough to be irreversibly brain damaged.
Or are we supposed to enforce the "average" value is actually the average? Rakudo still shits itself every time I try anything interesting with post-selection.
Name:
Anonymous2010-09-16 4:58
l=1 possibilities
max = average
l=2 possibilities
average = (max + n)/2
2*average = max + n
n = 2*average - max
n ≤ max
the following relationship must exist between the max and average for any valid situation
average ≤ max
l=3 possibilites
average = (max + n + m)/3
3*average-max=n+m
...
so
length*average-max=∑(other values which are ≥ max)
random integers
Until this definition is clarified further I will not participate. A randomly picked integer will almost surely contain more information than is possible to represent in this universe, even when it has a fixed maximum constraint.
By the way, let me assure you that you didn't come out witty, on the contrary, you are a typical victim of the multiple-choice-based education system, utterly unable to think otherwise than in the helpfully provided bounds.
>>37
Even if they are nonnegative (sic) integers, the randomly chosen upper bound will almost surely require more than any finite amount of space to represent.