LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-19-2016, 09:13 PM   #1
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Rep: Reputation: 24
Generating Pseudo-Random Numbers - Efficiency Question


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.

Thanks,
Doug
 
Old 09-19-2016, 09:52 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
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.
 
Old 09-19-2016, 10:13 PM   #3
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Original Poster
Rep: Reputation: 24
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
generating random numbers in C abk4523 Programming 20 01-10-2011 04:08 PM
generating random numbers for 10 minutes lucky.shubham Programming 4 10-21-2009 08:16 AM
Generating random numbers for C program J-Stew Programming 14 02-06-2004 04:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration