ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm doing something that I don't think has been done very often. I'm writing a character generator for a tabletop RPG. (Please note, that first sentence was irony.)
I'm considering two methods for rolling stats.
1. Roll the eight stats each time.
2. Include a two dimensional array, something like 10000x8 and only generate one random number from one to the length of the array. Whichever number is generated, take the eight values from that row. One advantage of this method is not worrying about a duplicate seed if I use srand(time(null)) to seed.
First, I'd like your thoughts on the two methods.
Second, I'd like your views on the efficiency of doing it either way.
Well, to be quite frank, "it has been done to death." However, there is always room for one more . . .
"Efficiency" notwithstanding (it absolutely does not matter ....), the question is simply whether-or-not you wish for your pseudo-random results to be biased:
If you do not want a bias, simply "roll the dice."
If, for the purposes of your game, you do wish to introduce bias, allocate a temporary array that will serve as "a deck of (sorted ...) cards," with whatever bias you wish to have, pre-programmed into the distribution of that deck. Then, select a card at random from that deck.
"Efficiency" is an irrelevant consideration. The statistical distribution of possible outcomes is the only criterion that applies, and all strategies for getting there are equally plausible.
In truth, I want to have it so the GM can decide about the bias. The game uses 3d6 to generate the stat. I'm going to give him the ability to set whether it's straight 3 to 18, 9 to 18, or a high power game, 12 to 18.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.