Generating a random number that can be accesed anywhere?

You don't actually call RandomNumberHandler() anywhere. Also, you need to specify your range in the call to Next() (e. G random.

Next(1000)+1 to get a number from 1 to 1000).

You don't actually call RandomNumberHandler() anywhere. Also, you need to specify your range in the call to .Next() (e.g. , random. Next(1000)+1 to get a number from 1 to 1000).

Public partial class Form1 : Form { //other stuff from before int randomNumber; //move this here public Form1() { randomNumber = random. Next(1, 1000); //assign it here InitializeComponent(); }.

But I want the random number to be defined outside the button, I don't want to call the random number inside it. Would this affect it? – Nogg Apr 15 '11 at 3:56 Then call the RandomNumberHandler method in the Form1 constructor.

– jonsca Apr 15 '11 at 3:58 It's saying something like " cannont convert method group 'GenerateRandomNumber' to non-delgate type int – Nogg Apr 15 '11 at 4:02 @Nogg: add the line randomNumber = random. Next(1, 1001); to the constructor, just after the line that reads InitializeComponent(); That will generate the random number. The reason it's always 0 right now is, as @jonsca pointed out, because you never call random.next().

– Jim Mischel Apr 15 '11 at 4:02 2 @Nogg: if @jonsca's response answered your question, you should accept it as the answer (click the check mark). – Jim Mischel Apr 15 '11 at 17:41.

Main problem is randomNumber is initialized when the constructor is called, and thereafter when you access it you access the same value. You should eliminate that instance variable, and instead simply make a new call to GenerateRandom(). In addition, you probably want to make your instance of Random a static variable: static Random random = Otherwise each time the class is unloaded and reloaded it will repeat the same sequence which would be less random (or rather, pseudo random).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions