Click here to Skip to main content
15,927,055 members
Home / Discussions / C#
   

C#

 
Questionvoid pointers and buffers Pin
sjdevo3gsr28-Nov-05 5:56
sjdevo3gsr28-Nov-05 5:56 
AnswerRe: void pointers and buffers Pin
leppie28-Nov-05 6:00
leppie28-Nov-05 6:00 
Questionproblem showing that a button's in focus Pin
melanieab28-Nov-05 5:24
melanieab28-Nov-05 5:24 
Questionautomate a login using AxWebBrowser Pin
mjmcinto28-Nov-05 4:34
mjmcinto28-Nov-05 4:34 
Questionget data from data set Pin
MffM28-Nov-05 4:31
MffM28-Nov-05 4:31 
AnswerRe: get data from data set Pin
Steve Maier28-Nov-05 4:40
professionalSteve Maier28-Nov-05 4:40 
Questionage = (byte)(generator.NextDouble() * 100 - 20); gives extremely high values Pin
ishlilith28-Nov-05 3:19
ishlilith28-Nov-05 3:19 
AnswerRe: age = (byte)(generator.NextDouble() * 100 - 20); gives extremely high values Pin
Guffa28-Nov-05 4:01
Guffa28-Nov-05 4:01 
Yes, your thought is correct. You are picking a random number between -20 and 79, when you cast that to a byte, the values -20 to -1 becomes 236 to 255.

Why are you picking a number between -20 and 79 anyway? That seems like strange values for something called "age"... Are you attempting to pick a number between 20 and 99?

Anyhow, take a look at the Next() method of the Random class. It returns an integer value that is greater or equal to 0 and less than the specified maximum. This code gives the same result as your code, and creates a value between 0 and 254:

dex = generator.Next(255);

If you want a random number where the lower range is other than zero, you can get a random number where the lower range is zero, and just add a constant value. This creates a value between 20 and 99:

age = generator.Next(80) + 20;

But then again, there already exists a method for this:

age = generator.Next(20, 100);

---

I see that you are declaring byte variables. Unless you have some special plan that requires byte size variables, stick to the int data type. The processor internally only uses two data types; int and double. If you use these, your code will be faster.

---
b { font-weight: normal; }

GeneralRe: age = (byte)(generator.NextDouble() * 100 - 20); gives extremely high values Pin
ishlilith28-Nov-05 4:18
ishlilith28-Nov-05 4:18 
AnswerRe: age = (byte)(generator.NextDouble() * 100 - 20); gives extremely high values Pin
Michael Potter28-Nov-05 4:02
Michael Potter28-Nov-05 4:02 
GeneralRe: age = (byte)(generator.NextDouble() * 100 - 20); gives extremely high values Pin
Steve Maier28-Nov-05 5:16
professionalSteve Maier28-Nov-05 5:16 
QuestioneRROR AND HOW TO RAPAIR IT Pin
papa198028-Nov-05 2:51
papa198028-Nov-05 2:51 
AnswerRe: eRROR AND HOW TO RAPAIR IT Pin
Stanciu Vlad28-Nov-05 4:47
Stanciu Vlad28-Nov-05 4:47 
GeneralRe: eRROR AND HOW TO RAPAIR IT Pin
papa198028-Nov-05 5:22
papa198028-Nov-05 5:22 
AnswerRe: eRROR AND HOW TO RAPAIR IT Pin
leppie28-Nov-05 5:57
leppie28-Nov-05 5:57 
GeneralRe: eRROR AND HOW TO RAPAIR IT Pin
papa198028-Nov-05 6:09
papa198028-Nov-05 6:09 
GeneralRe: eRROR AND HOW TO RAPAIR IT Pin
leppie28-Nov-05 6:20
leppie28-Nov-05 6:20 
GeneralRe: eRROR AND HOW TO RAPAIR IT Pin
Stanciu Vlad28-Nov-05 6:37
Stanciu Vlad28-Nov-05 6:37 
Questiongeting address of function in c# Pin
mostafa.hk28-Nov-05 2:14
mostafa.hk28-Nov-05 2:14 
AnswerRe: geting address of function in c# Pin
Stanciu Vlad28-Nov-05 4:52
Stanciu Vlad28-Nov-05 4:52 
AnswerRe: geting address of function in c# Pin
Dave Kreskowiak28-Nov-05 5:09
mveDave Kreskowiak28-Nov-05 5:09 
QuestionC# and dynamic report in cristal reports Pin
omichalowski28-Nov-05 1:53
omichalowski28-Nov-05 1:53 
QuestionProcess.HasExited property does not work as expected Pin
Ricardo Mendes28-Nov-05 1:40
Ricardo Mendes28-Nov-05 1:40 
AnswerRe: Process.HasExited property does not work as expected Pin
Stanciu Vlad28-Nov-05 5:05
Stanciu Vlad28-Nov-05 5:05 
QuestionAccessing PDA from an Application Pin
rnvrnv28-Nov-05 1:38
rnvrnv28-Nov-05 1:38 

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.