简体   繁体   中英

Excel - Return a value based on probability

So, I am making a generator to create a fictional character. In column "A" I have their possible races listed, and in "B" the likelyhood that a randomly generated character will be each one.

So the data looks like this Human (35%) Dwarf (30%) Elf (30%) Goblin (5%)

I understand RandomBetweem function, but i want to affect the output. Any help on this is appreciated!

There's probably a few ways to solve this. One way is to make a big fat list of of repeating values for each row that are built from your weights:

 =REPT(1,B1*100)&REPT(2,B2*100)&REPT(3,B3*100)&REPT(4,B4*100)

Which makes a list like:

1111111111111111111111111111111111122222222222222222222222222222233333333333333333333333333333344444

Then randomly grab one of those row numbers and select the corresponding value in the "A" column:

 =INDIRECT("A"&MID(REPT(1,B1*100)&REPT(2,B2*100)&REPT(3,B3*100)&REPT(4,B4*100),RANDBETWEEN(1,100),1))

I would have to think there is a more elegant way of going about this, but this seems reasonable for a smaller list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM