I have NSMutableArray named *arrWords containing list of 50 words. e.g. Bond/Bind/King/Sing/Ring etc.
I use following function to display random words on screen.
-(void)displayRandomWord //This is called from timer so it randomly shows words on screen
{
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(150,150,200,30)];
[lbl setText:[arrWords objectAtIndex:round([self randomXValueBetween:0 andValue:49])];
[self.view addSubView:[lbl]; //this label will be removed after 1 second I have written code for that.
}
- (float)randomXValueBetween:(float)low andValue:(float)high {
return (((float) arc4random() / 0xFFFFFFFFu) * (high - low)) + low;
}
This works fine. Now my problem is let say after certain amount of time I want to increase frequency of the particular word to be appear.
I want to setup logic like initially “Sing” is to be appeared 3 times in first 10 seconds. After 10 seconds I want it to be appear atleast 2 times more than 3 times (i.e. 5 times).
Because it is random picking of words “Sing” may appear 3 times in first 10 seconds or may not.
I am stuck here to setup logic. Any suggestions ?
My first thought was to increase the amount of word “Sing” after certain time.
What do I mean is this:
If I have 50 words. A chance to get a “sing” word is 1/50.
Now after 10 seconds I insert additional word “sing” to the array. Now I have 51 words in it.
My chance of getting word “sing” just increased to” 2/51.
That is the simplest way I could think of.
Hope that helps.
EDIT: I just thought that if you want to make sure that you have at least some amount.
You could do it like this.
If you know exactly how many words you will display in first 10 seconds? Example. 10 which is 1 per second. Then you could do this:
Pseudocode