comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Generating N random numbers that add to a TOTAL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Generating N random numbers that add to a TOTAL [message #89229 is a reply to message #89228] Wed, 06 August 2014 21:24 Go to previous messageGo to previous message
cgguido is currently offline  cgguido
Messages: 195
Registered: August 2005
Senior Member
Looking at the output of the above, it didn't seem like the numbers were uniformally distributed, so to speak...

Just had a thought:

If I generate N-1 numbers between 0 and TOTAL, then I could use the intervals between the sorted numbers no?

Something like:

n = 4
total = 100
r=randomu(seed,n-1)*total
sr=[r[sort(r)], total]
res= sr-shift(sr,1)
res[0] = sr[0]
print, res, total(res)

Still have problems if I round the result. Don't always get total(res)=TOTAL...
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to find the confidence interval of a variable data at 95% or 66%?
Next Topic: get_lun & free_lun

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 14:45:49 PDT 2025

Total time taken to generate the page: 0.56477 seconds