Click here to Skip to main content
15,895,084 members
Home / Discussions / C#
   

C#

 
GeneralSplit string by string Pin
dezoe19-Nov-02 6:43
dezoe19-Nov-02 6:43 
GeneralRe: Split string by string Pin
leppie19-Nov-02 11:12
leppie19-Nov-02 11:12 
GeneralRe: Split string by string Pin
Eric Gunnerson (msft)19-Nov-02 11:25
Eric Gunnerson (msft)19-Nov-02 11:25 
GeneralRe: Split string by string Pin
dezoe19-Nov-02 12:41
dezoe19-Nov-02 12:41 
QuestionEnabled ForeColor? Pin
Delegate19-Nov-02 6:41
Delegate19-Nov-02 6:41 
GeneralSqlReader.GetValues() problem Pin
leppie19-Nov-02 6:32
leppie19-Nov-02 6:32 
GeneralRemoving EnhancedMetafile from clipboard fails Pin
gharrison19-Nov-02 5:27
gharrison19-Nov-02 5:27 
GeneralCOM+ Windows API Pin
thematt19-Nov-02 2:52
thematt19-Nov-02 2:52 
GeneralRe: COM+ Windows API Pin
leppie19-Nov-02 11:07
leppie19-Nov-02 11:07 
GeneralRe: COM+ Windows API Pin
thematt20-Nov-02 2:21
thematt20-Nov-02 2:21 
GeneralBinding Collection to Datagrid Pin
thematt19-Nov-02 2:41
thematt19-Nov-02 2:41 
GeneralRe: Binding Collection to Datagrid Pin
leppie19-Nov-02 10:59
leppie19-Nov-02 10:59 
GeneralRe: Binding Collection to Datagrid Pin
thematt20-Nov-02 2:19
thematt20-Nov-02 2:19 
Questionhow to display the image formats (. gif) in crystal reports Pin
crodling18-Nov-02 20:24
crodling18-Nov-02 20:24 
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 

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.