#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Spliting a value into x random values


    I need to find a way to split up a value into multiple smaller values, adding up to said value.

    Splitting up 100 to 6 different values could look something like this:

    13, 25, 4, 42, 6 , 10

    My problem is that i need random numbers. I thought about just doing some loop stuff but it always ends up destroying any result. Because i'd get stuff like 40, 20, 40, 0,0,0.

    Loops are biased in this case. So i'd need some math solution for it. Or a workaround to fix this loop bias.

    Or.. anything really. I have the feeling it's really easy and i just don't see it :/
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Is there a maximum value that you could get to split? A varying number of splits? Any technical restrictions like memory usage or execution time?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0
    Well yea there is a maximum. I'm not sure what yet though. It might be somewhere around 10000. But as i said, i'm not sure yet, that might change. Maybe it's just around 1000, can't tell yet.

    If by "varying number of splits" you mean the amount of numbers i'd like to split the value on then yes. It'll be somewhere around a dozen. So it should work well for pretty much any number you throw at it.

    Memory usage shouldn't be important, as long as you don't go totaly nuts and start to talk about a few hundred MB or something :P

    Execution time is not really critical, but obviously it shouldn't take a whole second or something.

IMN logo majestic logo threadwatch logo seochat tools logo