|
Hi all, I am trying to randomly select a character set from a list to be used in my function but I can't get it to work, below is what I have thus far.
public const string myChars1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const string myChars2 = "abcdefghijklmnopqrstuvwxyz";
public const string myChars3 = "0123456789";
private string RandomString()
{
char[] buffer = new char[24];
int i = 0;
while (i < 23)
{
int k = 0;
string S = "";
Random myRandomNum = new Random();
Random myRandomNum2 = new Random();
k= myRandNum2.Next(1,3);
S = Convert.ToChar(k);
buffer[i] = myChars+S[myRandNum.Next(myChars+S.Length)];
i++;
}
return new string(buffer);
}
I am trying to tack S to the end of myChars so that I will get myChars1, myChars2, or myChars3 randomly but it's not working. How could I achieve this? Any suggestions is greatly appreciated, thanks in advance for your help.
modified 19-Jul-12 13:32pm.
|
|
|
|
|
Hi,
ASPnoob wrote: I can't get it to work
not informative.
ASPnoob wrote: it's not working
again, not informative. you've told that already. is it compiling? is it running without exceptions? are the results not what you hoped for?
A random number generator generates seemingly arbitrary numbers; it starts at some value, which depends on the seed you give it, or the current time. Your loop creates a new instance of class Random on each iteration, they will all run with the same initial value (as your program will last less than 1 millisecond), so there isn't much randomness at all.
Suggestion: create one and only one instance of Random and keep using it over and over.
|
|
|
|
|
|
If you're using a multitude of Random() objects, how will you give them arbitrary seeds? with another Random perhaps? And what would be the point of all that?
|
|
|
|
|
|
Right. I think that is well beyond the scope of this thread though.
|
|
|
|
|
Hi Luc, thanks for replying. The compiler is saying that myChars in the following line
buffer[i] = myChars + S[myRandNum.Next(myChars + S.Length)];
does not exist in the current context.
It's probably something simple and I'm scouring my book and the web for an answer.
modified 19-Jul-12 14:16pm.
|
|
|
|
|
You're not going to find an answer.
Where did you define myChars ?? It's nowhere in the code snippet you posted.
|
|
|
|
|
The compiler is right. (It usually is, you'll get used to that).
There is no variable called myChars declared anywhere in your code.
And you can't concatenate parts of a variable name like that, you need a completely different approach to get what you want. You might store the three strings in a string array, then use a random index into that array.
PS: please don't modify a post in such a way that earlier responses become meaningless or incomprehensible. Leave the original content, and if necessary add/modify and indicate you did. Like so:
[ADDED] new information goes here [/ADDED]
|
|
|
|
|
|
Thank you everyone, your responses have been very helpful. The problem is now solved. I decided to use an idea which some of you had suggested and that is to use the index of an array to achieve what I wanted.
|
|
|
|
|
Let's say I have a simple aspx page with a text box and a button. when the text box is filled and the button click, it will proceed to another page.
Now I want to use console app to make it run auto.
How can I do that?
|
|
|
|
|
|
I am prepared for the "wrong forum", "google the answer", "RTFM" replies but I have looked and found various methods of running a VB script, C++ dll etc. but none of how to execute an exe. The exe in question looks for a driver checks the version if its below the minimum it installs the minimum, if its above it does nothing. I guess that my question can also be seen as invite to all sorts of nasty code but!
Glenn!
|
|
|
|
|
Glenn, if you download the source to MoXAML PowerToys[^] I have added an installer that performs a custom action. Load the project and look at the project MoXAML.InstallHelper to see how I have implemented it.
In the file AddinInstaller.cs, modify the Install method to do what you need. One thing though - you don't need your code to be in a separate exe - you could actually put your check code in this helper, and call it from this method.
If you need to start an external program, all you need to do is call Process.Start to run that program (passing in the name and path of the executable).
|
|
|
|
|
Hi,
Done that this raises more questions. I was hoping that there would a quick method such as Process.Start(@"Driver.exe"); my question was how to use/implement a custom action as the MSDN version assumes you are doing A and only A, oooh heck I need
Glenn
|
|
|
|
|
I'm lost now. The code I've shown you shows HOW to write the custom install step. Are you not sure about how to add the custom install step?
If so, all you need to do (after adding a reference to your custom installer project into your installer) is to open up the Custom Actions node in the installer and right click on it. Choose Add custom action from the context menu then choose the assembly that contains your custom installer. And that's it - job done.
|
|
|
|
|
Sorry, I think that's what I needed to know, I think the issue was I had all the bits I wasn't sure or how to assemble it! (Airfix memory's )
Glenn
|
|
|
|
|
Sounds like we've finally got there. Huzzah.
|
|
|
|
|
Thanks, and sorry how MIL (last I heard thing were looking up)
|
|
|
|
|
She's good thanks. She's out of hospital and recuperating at home now. The operation was to remove part of her lower instestine and it seems to have gone without incident. She has to go back to the hospital tomorrow to be weighed and have her blood pressure taken, but we're hopeful that she's put this all behind her now.
|
|
|
|
|
I have created some web applications and now I want to create 'something' so that it will run everything automatically. I have no idea how can I do this. Anyone can give some lead? Is it I have to create dll and exe file?
|
|
|
|
|
Hi everyone, I would like to filter comboboxes. If I choose a certain value in one combobox, the following two comboboxes should only display the value of the first combobox or less. So lets say I choose an amount of 100 000.00 the following two comboboxes should only have 0 - 100 000.00 displaying in them. Any ideas on how to do this would be appreciated. Thanks for the help.
modified 19-Jul-12 7:33am.
|
|
|
|
|
Please tell me you aren't planning on having 100K items in a combobox. That would present a totally unusable interface for a user.
|
|
|
|
|
Sorry I should have been more clear. The amounts in the comboboxes are from 0 - 200 00.00 every 10 000.00 so 0, 10 000.00, 20 000.00 etc etc. Thanks
|
|
|
|