views:

452

answers:

4

basically i have a function that generates random alphabets .i have done this using the rand() function to generate numbers and them converted them to their corresponding ascii equivalents. but i want the vowels to be generated in higher numbers as compared to other alphabets.i.e if have generated say 10 alphabets then there should be like 2 o's,3 a's etc. how do i do this??in vc++6.0.

Edit: actually i am making scrabble as my college project in vc++6.0. so under my board i have 7 buttons on which i am displaying a random letter on each.so what i want is that ..like in scrabble we have:

 1 point:  E ×12, A ×9, I ×9, O ×8, N ×6, R ×6, T ×6, L ×4, S ×4, U ×4
 2 points: D ×4, G ×3
 3 points: B ×2, C ×2, M ×2, P ×2
 4 points: F ×2, H ×2, V ×2, W ×2, Y ×2
 5 points: K ×1
 8 points: J ×1, X ×1
10 points: Q ×1, Z ×1

so just like you would pick 7 random letters from the above described set, i want the 7 letters to be generatd in the same way.

A: 

give every value a weight. E.g. a=5, b=5, c=2, .... q=1, z=2 etc

the higher the weight, the more often you want the letter to appear

to calc a random letter, add all the weights together and pick a random between 0 and the totalweight.

then select the letter which corresponds with the drawn number:

as in the example: if you drew 0-4 you take the a, if you drew 5-9 you take b, 10-11 =c etc etc

Toad
actually i am making scrabble as my college project in vc++6.0.so under my board i have 7 buttons on which i am displaying a random letter on each.so what i want is that ..like in scrabble we have..1 point: E ×12, A ×9, I ×9, O ×8, N ×6, R ×6, T ×6, L ×4, S ×4, U ×42 points: D ×4, G ×33 points: B ×2, C ×2, M ×2, P ×24 points: F ×2, H ×2, V ×2, W ×2, Y ×25 points: K ×18 points: J ×1, X ×110 points: Q ×1, Z ×1so just like you would pick 7 random letters from the above described set, i want the 7 letters to be generatd in the same way.
A: 

A trivial solution is to use 2 lists. One with the vowels and one with consonants.
Now construct your new alphabet by selecting N random vowels and M random consonants where N > M and N+M = max size of alphabet.

Nick D
actually i am making scrabble as my college project in vc++6.0.so under my board i have 7 buttons on which i am displaying a random letter on each.so what i want is that ..like in scrabble we have..1 point: E ×12, A ×9, I ×9, O ×8, N ×6, R ×6, T ×6, L ×4, S ×4, U ×42 points: D ×4, G ×33 points: B ×2, C ×2, M ×2, P ×24 points: F ×2, H ×2, V ×2, W ×2, Y ×25 points: K ×18 points: J ×1, X ×110 points: Q ×1, Z ×1so just like you would pick 7 random letters from the above described set, i want the 7 letters to be generatd in the same way.
+1  A: 

You could add another rand function. F.e. (sorry, this is just pseudo code)

if(rand(0,10) >= 5) {
    //generate here a vowel at random
} else {
    //generate a normal letter or a random letter (including vowel)
}

This will generate vowels at a 50/50 chance, you can change this chance by altering the 5.

Bobby

Bobby
actually i am making scrabble as my college project in vc++6.0.so under my board i have 7 buttons on which i am displaying a random letter on each.so what i want is that ..like in scrabble we have..1 point: E ×12, A ×9, I ×9, O ×8, N ×6, R ×6, T ×6, L ×4, S ×4, U ×42 points: D ×4, G ×33 points: B ×2, C ×2, M ×2, P ×24 points: F ×2, H ×2, V ×2, W ×2, Y ×25 points: K ×18 points: J ×1, X ×110 points: Q ×1, Z ×1so just like you would pick 7 random letters from the above described set, i want the 7 letters to be generatd in the same way.
A: 

I'll write it in pseudo-code. Let's say you have your letter frequencies defined:

freq['a'] = 0.2
freq['b'] = 0.01
...
freq['z'] = 0.02

Sum of all elements should obviously be 1.

Then you can define an array with intervals:

intr['a'] = [0; 0.2)
intr['b'] = [0.2; 0.01)
...
intr['z'] = [0.98; 1)

Then when you generate a random number n in interval [0; 1), you just need to run through interval array and find which letter corresponds to that:

for(letter = 'a' .. 'z')
  if n in intr[letter] then return letter;

The interval array can also be implemented using integer numbers for speed.

Superfilin
actually i am making scrabble as my college project in vc++6.0.so under my board i have 7 buttons on which i am displaying a random letter on each.so what i want is that ..like in scrabble we have..1 point: E ×12, A ×9, I ×9, O ×8, N ×6, R ×6, T ×6, L ×4, S ×4, U ×42 points: D ×4, G ×33 points: B ×2, C ×2, M ×2, P ×24 points: F ×2, H ×2, V ×2, W ×2, Y ×25 points: K ×18 points: J ×1, X ×110 points: Q ×1, Z ×1so just like you would pick 7 random letters from the above described set, i want the 7 letters to be generatd in the same way.