Page 1 of 1

Weighted Random Numbers

Posted: Sun Apr 18, 2004 2:30 pm
by burzvingion
Hello im a noob to this forum but anywho...

Im making a random word generator for my made up language (aka Conlang) called Ceenera and have gotten to the point where i want the user to be able to choose a range of syllables for the resultant words, as well as the "nominal" number of syllables to use, so that its more likely that a word will be closer to the nominal number of syllables than the bounds. ie. the user inputs via a form:
min: 1 syllable
nom: 2 syllables
max: 5 syllables
num of words: 1000

the results might be something like:
101 words with 1 syllable
499 words with 2 syllables
210 words with 3 syllables
139 words with 4 syllables
51 words with 5 syllables

The problem is, rand() and mt_rand() allow you to specify a range, but everything in that range is equally probable to be chosen. If anyones ever made a script like this before it would be much appreciated!
viel dank!

Posted: Wed Apr 21, 2004 2:25 pm
by Weirdan
yeah, there is such script in Code Snippets forum ;)

viewtopic.php?t=15769&highlight=

ty

Posted: Sat May 29, 2004 1:16 pm
by burzvingion
ok thanksmuch! i think that'll work