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

    Join Date
    Jul 2013
    Posts
    1
    Rep Power
    0

    Random generator


    What type of program is needed to make
    a randon percentage generator for multiple inputs.
    Example would be a scavenger looking for items
    and the generator would set the out put of what the player finds and how much of it or the condition of it based on a list of what he could find and the percentage of his chances to find them. i hope i explained thi right.
    player searches and has the ability to find items how many and what condition they are in will have to be generated based on differents percentages.

    Thank you for reading this

    Wayne
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
    Every programming language I know of has a way to get a random number. Get one and divide by the largest possible value + 1 to get a percentage. (Often you can just get a decimal number immediately without having to do any division yourself.)

    Then go through your list of items until you find one where the current sum of past items' chances <= random percentage < current sum + current item's chance.

    Example:
    Code:
    random chance = 0.26758%
    
    items:
    - apple (0.10%)
    - blueberry (0.15%)
    - crayon (0.25%)
    - dead mouse (0.50%)
    
    1. apple      sum=0     chance=0.26  sum+item=0.10
    2. blueberry  sum=0.10  chance=0.26  sum+item=0.25
    3. crayon     sum=0.25  chance=0.26  sum+item=0.50 <--

IMN logo majestic logo threadwatch logo seochat tools logo