|
What I mean is for example
2, 7, 88, 33, ....
There are 100000 elements and 1 number created once , but they are random orders.
Not this: 2, 8 , 7 , 8, 7....
Sorry
Pls help
eric
|
|
|
|
|
Random r=new Random();
for(int k=0;k<=10000;k++)
{
int x=0;
int b[k]=r.next(x,10000)
x=x+1
}
Not a really good solution but it will work !?!;)
nemanja
|
|
|
|
|
Yeah,
That's true
Thanks anyway
eric
|
|
|
|
|
Like J4amieC suggested I would start by creating an array containing all your numbers sorted. Then just switch the numbers randomly in x iterations. Pick two random indices between 0 and 99999 and switch the two values in the array. If you make this long enough (probably 1 million times) than they should be ordered rather randomly.
int[] list = new int[100000];
for (int i = 0; i < list.Length; i++)
list[i] = i;
Random r = new Random();
for (int i = 0; i < 1000000; i++)
{
int i1 = r.Next(0, list.Length);
int i2 = r.Next(0, list.Length);
int temp = list[i1];
list[i1] = list[i2];
list[i2] = temp;
}
int counter = 0;
for (int i = 0; i < list.Length; i++)
if (i == list[i])
counter++;
|
|
|
|
|
Very smart solution
Thanks so much Robert
I'm fixing now
eric
|
|
|
|
|
Does any statistical wizard know exactly how much you'd need to randomly swap items like this before you had something that you could say wasn't biased by the fact that the items started in order?
I'm just curious.
BTW, what's the last for loop for?
|
|
|
|
|
I think it should be pretty simple for a statician (does this word exist?). Just calculate how likely it is that one index in the array isn't hit and multiply this with the length of the array.
Wjousts wrote: BTW, what's the last for loop for?
It was for myself trying to determine if one million switches would be enough. My tests mostly said that 0-2 elements were at its original position. Whether this was because they weren't hit by the algorithm or if they were just reswitched I don't know .
|
|
|
|
|
Robert Rohde wrote: It was for myself trying to determine if one million switches would be enough. My tests mostly said that 0-2 elements were at its original position. Whether this was because they weren't hit by the algorithm or if they were just reswitched I don't know .
That's what I thought you might be doing, but I think the logic to that might be flawed. You'd expect at least a few elements to be in the correct place just by chance. If five items just happen to end up in the correct place it doesn't mean the sequence isn't random. Even a random sequence could (in theory) end up being in exactly the right order.
|
|
|
|
|
You are absolutely rihgt. I just added it for me to check whether it is 'somehow random'. If the result would have been something like 1000 (I think the chance of having such a large number of items at their exact location should be near to zero) than I would not have posted the code .
|
|
|
|
|
That's pretty cool, but surely has the danger that numbers won't ever get hit and moved elsewhere, so you end up with a pretty random list with a few numbers exactly where they started.
Instead of swapping randomly, why don't you go through the array sequentially, and swap each number with a random one?
Regards,
Rob Philpott.
|
|
|
|
|
I've done something very similar several times (not as much as 100,000 though). The way I did it was this:
int[] myArray = new int[100000];
Random rnd = new Random();
ArrayList number = new ArrayList(100000);
for (int i=0; i<100000; i++)
{
number.Add(i);
}
for (int i=0; i<100000; i++)
{
int temp = rnd.Next(numbers.Count);
myArray[i] = numbers[temp];
numbers.RemoveAt(temp);
}
I populate an ArrayList with all the numbers and then randomly pull them out of the list and put them in my array. I don't know how efficient it'd be for 100,000 items though.
|
|
|
|
|
Hiiii,
I want to change the color of scroll bars...like u can see in Windows xp forms having a blue color scroll bar.
thanx
Anuj Kamthan
Software Developer
Solversa Technologies,
Pune - 411007, India.
http://www.solversa.com
|
|
|
|
|
Hiii,
I m Working on an c# Desktop Application i need to change the color of scroll
bars...
Anuj Kamthan
Software Developer
Solversa Technologies,
Pune - 411007, India.
http://www.solversa.com
|
|
|
|
|
The WinForms platform does not provide a way to modify the appearance of a scrollbar. There is probably some way to accomplish that via P/Invoke. If that does not tickle your fancy, you can buy third-party controls (like the Infragistics NetAdvantage) and use their customizable scrollbars.
Josh
|
|
|
|
|
I have a class property that I want to be localisable. The MSDN gives an example as:
<br />
[<br />
Description ( "The name of this section" ),<br />
Category ( "Section" ),<br />
DisplayName ( "Section name" ),<br />
Localizable ( true )<br />
]<br />
public int MyProperty {<br />
get {<br />
return 0;<br />
}<br />
set {<br />
}<br />
}<br />
The help files say
When code is generated for a component, members that are marked with the
LocalizableAttribute set to true have their property values saved in resource
files. You can localize these resource files without modifying the code.
So I would expect all the attributes to appear in the .resx file, but they don't. Is this a bug, or am I doing something wrong?
|
|
|
|
|
I think you must also set Localizable of the Form the control is placed on also to true.
|
|
|
|
|
The class isn't on a form.
It's just a holder for information that can be used by PropertyGrid.
|
|
|
|
|
I wont my app workon mobile phone who support java.
But my app is writen in c# how can i convert it!
Thanks!!
nemanja
|
|
|
|
|
I believe you'll need to convert your C# code to Java.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Yes do you have it .Or does it really exist.
nemanja
|
|
|
|
|
No, you'll need to convert it manually. See this[^] link for more info.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
|
I wont my app work on moile phone .I create my app in c# .I dont know java but i was thinking i can get convertor but i can't find the convertor.
nemanja
|
|
|
|
|
well... with SharpZibLib you can create jar files ... it is like creating zip files but in stead of .zip it's .jar ...
|
|
|
|
|
Does convertor exists.
nemanja
|
|
|
|