Re: 10% probability of dying
What do you mean by die? Should the label be..removed?
Re: 10% probability of dying
With a number that low, it may not pay to do anything fancy with collections or anything, just loop from 0 to 24, picking a random number between 0-100 (the top value is not used in Random.GetNext, so 0-100 is right). If the number comes up less than 10, then that label dies. The only difficulty would be deciding which label each iteration of the loop was dealing with, but that shouldn't be hard.
Of course, as Atheist pointed out, we don't know what "dies" means in terms of a label.
You could make a pun out of it, by simply changing it's color.
Re: 10% probability of dying
Quote:
Originally Posted by Atheist
What do you mean by die? Should the label be..removed?
10% of the labels are to go each time you press a button
Re: 10% probability of dying
to go :ehh: ...well then i presume you mean that they should be removed ;)
Shaggy hiker has said it all :D
Re: 10% probability of dying
Sounds like a school project? What have you done so far?
Re: 10% probability of dying
I would go along these lines. A 5x5 grid sounds like a good use of a TableLyoutPanel. You'd place your 25 Labels in the cells of the table and then do something like this:
VB Code:
Dim myRandom As New Random
For Each lbl As Label in myTableLayoutPanel.Controls
If myRandom.Next(0, 10) = 0 Then
'Kill the Label.
lbl.Dispose()
myTableLayoutPanel.Controls.Remove(lbl)
End If
Next lbl
Re: 10% probability of dying
Quote:
Originally Posted by RobDog888
Sounds like a school project? What have you done so far?
Not quite a school project, manage to get diffrent labels disappear at as random variable but not to the 10% dying time that was asked of the task
Re: 10% probability of dying
Or more specifically even:
VB Code:
Private myRandom As New Random
Private Sub KillLabels(ByVal likelihoodOfDeath As Integer)
Debug.Assert(likelihoodOfDeath > 0 AndAlso likelihoodOfDeath <= 100)
For Each lbl As Label in myTableLayoutPanel.Controls
If myRandom.Next(0, 100) < likelihoodOfDeath Then
'Kill the Label.
lbl.Dispose()
myTableLayoutPanel.Controls.Remove(lbl)
End If
Next lbl
End Sub