+ Reply to Thread
Results 1 to 8 of 8

World Population Random Generator

  1. #1
    Registered User
    Join Date
    04-18-2015
    Location
    East of Central
    MS-Off Ver
    Excel Online
    Posts
    7

    World Population Random Generator

    I have a spreadsheet with three columns: the names of 261 countries and territories, their respective population counts and the percentage of the world population total that each nation represents.

    I'm trying to make a random generator that will produce the name of one of these countries, where the probability that a particular country's name comes up is equal to the percentage of the world population that it represents. For example, China's population accounts for 18.8617605386887% of the world population, so the odds of my generator producing "China" should be 0.188617605386887.

    Haven't been able to get it to work, and I've asked a few friends. Any help?

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: World Population Random Generator

    Use a 4th column to add up those percentages cumulatively, i.e. in D2 use this formula:

    =C2+D1

    Copy the formula down to the bottom of the list, and put zero in D1.

    Then elsewhere you can use this formula:

    =INDEX(A:A,MATCH(RAND(),D:D,1))

    and copy this down for 10 rows. You can generate another list by pressing F9.

    Hope this helps.

    Pete

  3. #3
    Registered User
    Join Date
    04-18-2015
    Location
    East of Central
    MS-Off Ver
    Excel Online
    Posts
    7

    Re: World Population Random Generator

    Thanks, Pete!

    This solution is closer than anything I've tried, and a lot simplier. But it seems to have a bug in it: the Pitcairn Islands are showing up far, far too often.

    Attachment 435124

    The Pitcairn Islands have the lowest population of any organized territory in the world - a mere 56 people, accounting for 0.0000000077 of the world population. If the generator assigns probability based on population, it's extremely unlikely that the Pitcairn Islands show up even once in a thousand tries, let alone three times in ten.

    I think it's because the Pitcairn Islands are at the end of the list, which is sorted by the B column. Did I make an obvious mistake, or is there some bug in the code?

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: World Population Random Generator

    I can't download your attachment - the system says that it is invalid. Follow the steps given in the FAQ to attach a file, i.e. click on Go Advanced while in edit mode on a post, scroll down and click on Manage Attachments, click on Browse and navigate to where the file is on your PC, then double-click it, click on Upload and Close Window, the Submit Post.

    Pete

  5. #5
    Registered User
    Join Date
    04-18-2015
    Location
    East of Central
    MS-Off Ver
    Excel Online
    Posts
    7

    Re: World Population Random Generator

    Thank you. Here is a screenshot of my file:

    Screenshot 2015-12-13 at 7.50.11 PM.png

    And this is the file itself:

    World Populations.xlsx

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: World Population Random Generator

    In D2 and copy down:

    =C1 + D1
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: World Population Random Generator

    The bottom value of column D should equal 1, as that is 100% of the population. The fact that it doesn't means there is something wrong, and it is because I thought you would have a header row. I've corrected this and attached a new file. I've amended the formula in E1 to this:

    =INDEX(A:A,MATCH(RAND(),D:D)+1)

    and copied that down.

    Hope this helps.

    Pete
    Attached Files Attached Files

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: World Population Random Generator

    I would do it like this:

    Row\Col
    A
    B
    C
    D
    E
    F
    G
    1
    Country
    Pop
    %age
    LUT
    2
    China
    90
    0.900
    0.000
    D2: =SUM(C1:D1)
    0.227981061
    China
    3
    India
    10
    0.100
    0.900
    0.204641412
    China
    4
    0.118028084
    China
    5
    0.333002558
    China
    6
    0.902475866
    India
    7
    0.579516928
    China
    8
    0.881442124
    China
    9
    0.695200101
    China
    10
    0.883110586
    China
    11
    0.363493999
    China
    12
    0.361990320
    China
    13
    0.524942046
    China
    14
    0.153411008
    China

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Income percentile for world population
    By commexjimmy in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-09-2015, 04:50 AM
  2. Replies: 5
    Last Post: 06-21-2013, 10:40 AM
  3. Random Name Generator
    By jsbryan in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-13-2012, 10:44 AM
  4. random name generator
    By rookie37 in forum Excel General
    Replies: 16
    Last Post: 06-23-2009, 03:00 AM
  5. Random Generator
    By Duncan1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-11-2007, 08:07 PM
  6. random name generator
    By SRussell in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-25-2007, 06:28 PM
  7. Random Name Generator
    By Smeeg in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-03-2006, 11:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1