a question

didnt rly know how to name the thread subject, anyway

how do i make it impossible to have a certain number in a label? i have my numbers generated by aRandom() and if MyInt = 1 i want that 5 doesnt appear even if it says it has to appear (from my random list)

i hope u know what i mean

thx in advance

[430 byte] By [RubenPieters] at [2007-12-24]
# 1

Where are you getting the "MyInt" value from?

If you have numbers generated randomly using the Random() class, you can keep generated the number after say, a small delay of a few milliseconds (Thread.Sleep()) until the number generated is not the value desired.

Example:

Random theRandom = new Random();

int theNumberChosen = 5; //5 for example, the number you do not want to have chosen

while (theNumberChosen == desiredValue) //5 for example, while the number chosen is 5

{

Thread.Sleep(100);

theNumberChosen = theRandom.Next(0, maxValue);

}

The Thread.Sleep() gives a chance to delay the way the Random class operates, meaning it uses the time as a seed for itself I believe, but do not quote me - different times (milliseconds for example) results in a different number being produced.

I hope this explains it better but also hope you can give us more information about where this MyInt value is being generated from.

The logic is to keep doing something whilst the number you are after evaluates to true, it will eventually not be true causing it to stop/breaking out of the loop so you can continue

ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 2

Hi,

Hmmm.. Could you be more specific?

As I understand you are generating random numbers? and you don't want a number to appear?

string unwanted_num = "5";

int rand = <Generate Random Number>;

Label1.Text = rand.ToString().Replace(unwanted_num, "");

cheers,

Paul June A. Domag

PaulDomag at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 3

MyInt is just some integer that is 1 after i click a button

but i only want 5 not to appear if it is 1, and my random() goes from 1 to 15 and it puts it numbers in the label, but after i clicked the button(MyInt is now 1) once the random() goes 5, i want to not have it come on the label(everytime the random() has 5)

i dont rly understand what youre saying, but i dont think thread.sleep would be something good to use as everytime it turns 5, the form will sleep a sec and that would be annoying when using the form (i think) maybe it is possible to skip the 5 everytime random() has it as integer?

RubenPieters at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 4
RubenPieters wrote:

MyInt is just some integer that is 1 after i click a button

but i only want 5 not to appear if it is 1, and my random() goes from 1 to 15 and it puts it numbers in the label, but after i clicked the button(MyInt is now 1) once the random() goes 5, i want to not have it come on the label(everytime the random() has 5)

i dont rly understand what youre saying, but i dont think thread.sleep would be something good to use as everytime it turns 5, the form will sleep a sec and that would be annoying when using the form (i think) maybe it is possible to skip the 5 everytime random() has it as integer?

Hi,

Sorry, I completely misunderstood. Why not just perform a simple checking whenever your generating a new random number?

int newRandom = <Generate Random Number>;

if (MyInt == 1 && newRandom == 5) {

// don't display the random number in a label

} else {

// display it

Label1.Text = newRandom.ToString();

}

cheers,

Paul June A. Domag

PaulDomag at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 5

oh w8 nvm :<

RubenPieters at 2007-8-31 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...