|
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; }
|
|
|
|
|
Thanks, the book Im reading only tells about the NextDouble method.
And thanks for the additional input, as I said Its only my third day.
I wanted to get ages between 5 and 80 BTW
|
|
|
|
|
It is hard to tell what you are trying to accomplish. I will take a guess - you are trying to create a random positive integer.
Take a look at the Random.Next(int maxValue) method.
For a human age you might use code like:
int age = generator.Next(100) + 1;
This would give you an age between 1 and 100. Casting the result of a double to a byte may not give you the randomness you desire.
|
|
|
|
|
You can also use this.
int age = generator.Next(5,80);
And it will generate one between 5 and 80 with one simple step.
Steve Maier, MCSD MCAD
|
|
|
|
|
hi
i have program on c# with ms sql.when i start the program on my comp is work excelent but when i install it on some other i get this message(install=copy program and paste it on other computer)how to deside the problem??
"APPLICATION HAS GENERETE AN EXCEPTION THAT CLOUD NOT BE HADNLED PROCES ID=0X75(1884),THREAD ID=0X6F8(1784)
Thank you
|
|
|
|
|
papa1980 wrote: "APPLICATION HAS GENERETE AN EXCEPTION THAT CLOUD NOT BE HADNLED PROCES ID=0X75(1884),THREAD ID=0X6F8(1784)
As your error says, an exception was generated, and probably you do not have a try/catch block in witch to handle it. Your exception may have occured because you rely on something that is on your computer and on others may not be...
Put a try/catch block in your main procedure and display the exception's message to find out why your application crashes on other sistems.
protected internal static readonly ... and I wish the list could continue ...
-- modified at 15:11 Monday 28th November, 2005
|
|
|
|
|
I have it
static void Main()
{
try
{
Application.Run(new MainForm());
}
catch(Exception exp)
{
MessageBox.Show(exp.ToString());
}
}
this problem is occure not when i compilate the program on my computer is ocrure when i copy the program on other computer and try to use it????
|
|
|
|
|
|
ok i have it.My program is work one time correct and one not ???? when is on other computer why ????
|
|
|
|
|
|
I have one single thing to say : LoL
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Hello:
i want to write a interrupt in c# but i don't now how can i get address of my function that i want to use it for ISR.
how can i do it?
|
|
|
|
|
In order to achive such things you must juggle with reflection, unmanaged code, marshaling and others ... not a very easy thing in c#
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
C# is most definitely NOT suitable for this. C# doesn't have direct access to the hardware because of Windows Hardware Abstraction Layer. Your best bet for this sort of thing is C++ and the Windows Device Driver Development Kit. You have to write a Ring 0 .DLL that runs behind the HAL and exposes an interface for your C# app to use.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello,
I'm working with vs.net 2003 in C#. I don't know how to create an empty report in cristal reports and then bind a DataSet. My goal is to change a sql statement in runtime. I think the easiest way to do this is by binding the dataset.
I came accross to some tutorials but the code like this does not want to work:
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
Empty_cr report = new Empty_cr();
report.SetDataSource( ds);
crDataViewer.ReportSource = report;
Why? What is the reason?
Maybe someone knows a really good tutorial?
Could anyone help me? Please!! This is very important for me and can simplify some things.
Regards:
Olg
|
|
|
|
|
I've created a windows service to ensure another service is running. First of
all, I look for the process relative to the service I'm monitoring. The code
is:
Process[] processes = Process.GetProcesses();
foreach(Process process in processes)
if(!process.HasExited &&
process.Id > 0 &&
process.ProcessName.ToLower() != "system" &&
process.MainModule.FileName.ToLower() == serviceDetail.ExecutablePath.ToLower())
...
The problem is with the MainModule property, called at the end of the if
statement. Internally, the MainModule property gets all modules for the
process and looks for the main one. So, if the process has exited, the search
for the process modules fails and we get an exception.
In order to solve this issue, I test the HasExited property at first place.
However, I still get an exception: "Cannot process request because the
process (3248) has exited." Why this exception occurs if I have tested the
HasExited property? Am I doing somethig wrong or missing something?
Another exception is thrown too. Sometimes I get an "Access is denied"
exception from this code piece.
Does anyone have any idea that could help me?
Thanks in advance.
Ricardo
|
|
|
|
|
Ricardo Mendes wrote: "Cannot process request because the
process (3248) has exited." Why this exception occurs if I have tested the
HasExited property? Am I doing somethig wrong or missing something?
A process is independent from your code. If a process is now running, in a couple of clock cicles can enter in an different state, in the same time that you do an other operation (let's say adding two numbers). I think you should try to lock your code when you execute it.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Hi,
From my normal application running in my computer i need to connect to PDA and send some data or activate a method.
An PDA application (.net based) is already running in the PDA.
what is the best way to do it? will really appreciate
regards,
rnv
|
|
|
|
|
Hi All,
I want to have a nested class which is generally accessible, but can only be instantiated by it's containing class. ie:-
public class Parent
{
public class Child
{
<ParentOnly> Child();
}
public Child GetANewChildObject()
{
return new Child();
}
}
C# doesn't seem to directly support this - the closest you can get is with the internal access modified, which is sub-optimal.
The only real solution i've found is to implement the child class in 2 classes- an abstract Child, and a private Child2 : Child . But that seems a bit clumsy. Is there a better way?
Thanks
Jon
using System.Beer;
|
|
|
|
|
I think the 2nd way you suggested is the most limiting while still being usefull. The internal approuch doesnt really 'block' it. Another option to limit it even more is to make the abstract class protected, or the inheriting class protected for less limitation. You can get quite funky with nested layouts.
xacc.ide-0.1 released! Download and screenshots
|
|
|
|
|
Hi,
I have a Widow service. I am installing the service and related applications using install shield. i have written a service installer class. This works fine when i am installing or Modifying the application using setup file.
It gives problem when i repair the application, since the service is already exist. I have tried to stop installing the service if it exists in the system but still it gives me error "Unsave state...". In service installer class i have override install and uninstall method.
Is there any other way ot handle this.
Please give your suggetions.
Thanks & Regards
Basant
-- modified at 8:13 Tuesday 29th November, 2005
|
|
|
|
|
Hi,
I have a c# windows application with sys tray and a shortcut in desktop. There is no provision for minimizing the application window, so if i close the application i can re-open it from sys tray. Now the problem is that if i click on the shortcut, which is availabe on desktop, the application should open.
I have implement this partially, means i have closed all the process of the application and open a new one. For this i have used GetProcessesByName() function which is not worked in XP & Win 2k. I think it will better if the application already availabe in sys tray will open without killing the process while I clicking on desktop shortcut.
Please give your helpful comments.
Regards,
Basant
-- modified at 8:15 Tuesday 29th November, 2005
|
|
|
|
|
i have seen many about converting string to hex solution but yet to see any solution on converting hex to string.
i have been cracking my brain on converting hex to string. so i am wondering anyone can help me out on this problem.
Thank you
orrjiao
|
|
|
|
|
What do you mean, really? A hexadecimal value is a string representation of a number. A number in itself is not hexadecimal, it's just a number. A numeric base is only relevant when representing a number in string format.
Do you mean that you want to convert a string containing the hexadecimal representation of a number into a number?
---
b { font-weight: normal; }
|
|
|
|
|
i am sorry bout the unclear question i have post up.
yes, i am finding solution on coverting string of hexadecimal to decimal.
so is there any method i could use to slove this problem?
thank you.
orrjiao
|
|
|
|