Click here to Skip to main content
15,887,256 members
Home / Discussions / C#
   

C#

 
Generalwhere to find basic discuss or tutorial about... Pin
zhoujun18-Nov-02 19:15
zhoujun18-Nov-02 19:15 
GeneralRe: where to find basic discuss or tutorial about... Pin
leppie19-Nov-02 0:08
leppie19-Nov-02 0:08 
GeneralRe: where to find basic discuss or tutorial about... Pin
zhoujun19-Nov-02 13:19
zhoujun19-Nov-02 13:19 
GeneralRandom Numbers Pin
Member 1810818-Nov-02 18:37
Member 1810818-Nov-02 18:37 
GeneralRe: Random Numbers Pin
David Stone18-Nov-02 19:08
sitebuilderDavid Stone18-Nov-02 19:08 
GeneralRe: Random Numbers Pin
Senkwe Chanda18-Nov-02 20:58
Senkwe Chanda18-Nov-02 20:58 
GeneralRe: Random Numbers Pin
Member 1810818-Nov-02 21:49
Member 1810818-Nov-02 21:49 
GeneralRe: Random Numbers Pin
James T. Johnson19-Nov-02 14:46
James T. Johnson19-Nov-02 14:46 
The problem is that every time you call AssignColor, a new Random object is generated and is seeded using the current system time. This happens EVERY time you call AssignColor; so what happens is you call it the first time, it seeds the RNG (Random Number Generator), gets a value, then goes to the next block, seeds the RNG (using the same system time because not enough time has elapsed, spits out the same number, etc...

Solution: Instead of creating more than one Random object, make the Random object a static member of the BlockClass class; and use it like so...

class BlockClass {
  static Random r = new Random();
 
  // ....
 
  public void AssignColor()
  {
    switch(BlockClass.r.Next(4))
    {
      // ....
    }
  }
 
  // ....
}
Doing so ensures that only one instance of the Random class is generated so you can actually pull more than one number out of it.

James

- out of order -
GeneralRe: Random Numbers Pin
Member 1810819-Nov-02 20:54
Member 1810819-Nov-02 20:54 
GeneralRe: Random Numbers Pin
LongRange.Shooter19-Nov-02 11:03
LongRange.Shooter19-Nov-02 11:03 
Generalmake it dead. Pin
imran_rafique18-Nov-02 15:19
imran_rafique18-Nov-02 15:19 
GeneralRe: make it dead. Pin
Rickard Andersson2018-Nov-02 20:48
Rickard Andersson2018-Nov-02 20:48 
GeneralRe: make it dead. Pin
imran_rafique19-Nov-02 16:24
imran_rafique19-Nov-02 16:24 
GeneralMagic TabPage question Pin
m_mond18-Nov-02 15:16
m_mond18-Nov-02 15:16 
GeneralRe: Magic TabPage question Pin
leppie19-Nov-02 0:04
leppie19-Nov-02 0:04 
GeneralVisible Property Not Working Pin
Jamie Nordmeyer18-Nov-02 7:35
Jamie Nordmeyer18-Nov-02 7:35 
GeneralRe: Visible Property Not Working Pin
David Stone18-Nov-02 8:48
sitebuilderDavid Stone18-Nov-02 8:48 
GeneralRe: Visible Property Not Working Pin
Jamie Nordmeyer18-Nov-02 9:32
Jamie Nordmeyer18-Nov-02 9:32 
GeneralRe: Visible Property Not Working Pin
David Stone18-Nov-02 10:22
sitebuilderDavid Stone18-Nov-02 10:22 
GeneralCOM+ Pin
Mazdak18-Nov-02 5:50
Mazdak18-Nov-02 5:50 
GeneralXML questions ... Pin
LongRange.Shooter18-Nov-02 5:28
LongRange.Shooter18-Nov-02 5:28 
GeneralRe: XML questions ... Pin
Christian Graus18-Nov-02 15:34
protectorChristian Graus18-Nov-02 15:34 
GeneralRe: XML questions ... Pin
Nick Parker18-Nov-02 17:22
protectorNick Parker18-Nov-02 17:22 
GeneralRe: XML questions ... Pin
Christian Graus18-Nov-02 17:28
protectorChristian Graus18-Nov-02 17:28 
GeneralRe: XML questions ... Pin
LongRange.Shooter19-Nov-02 3:25
LongRange.Shooter19-Nov-02 3:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.