|
What I have done for that sort of thing is to have another table with two columns; one for the IDs of records in the main table and populate the other column with random numbers.
When it's time to select records; clear out the table, populate the table, then query the table, sorting by the random number column, and use the first 50 (or whatever) IDs.
You could simply add a random number column to the main table, but my process was trickier than that.
|
|
|
|
|
hope this helps!
First, read all the names from the excel file, probably into an array.
then, use some randomizing technique, and maybe a loop, to select your group.
and lastly, while selecting, write the names to a text file.
He who goes for revenge must first dig two graves.
|
|
|
|
|
Creamboy wrote: then, use some randomizing technique
Riiight... isn't that the part he's asking about? 
|
|
|
|
|
Put the available names in an array, then this method will pick the specified number of strings from it:
private string[] PickFrom(string[] values, int count) {
Random r = new Random();
string[] result = new string[count];
for (int i = 0, index = 0; index < count; i++) {
if (r.Next(values.Length - i) < count - index) {
result[index++] = values[i];
}
}
return result;
}
Usage:
string[] group = PickFrom(listOfNames, 50);
Note: The names in the returned array will be in the same order relative to each other as in the original array. If the original array is sorted, the resulting array will also be.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi Guffa,
I like that approach very much.
I was puzzled though by the details of the conditional test.
Shouldn't all candidate values get the same probability?
IMO the test should read if ( r.Next(values.Length) < count )
so each value[i] has probability count/value.Length
[ADDED] I see now. With fair probabilities, the algo may fail altogether,
when r decides to return lots of large numbers. So you are cheating a bit
to make it work all the time, at the expense of the first elements in the array,
since your probabilities are increasing at first.
Very clever. A little explanation was in order though.
[/ADDED]
|
|
|
|
|
Luc Pattyn wrote: Shouldn't all candidate values get the same probability?
IMO the test should read if ( r.Next(values.Length) < count )
so each value[i] has probability count/value.Length
All the candidates get the same probability. The probability for each candidate depends on how many of the previous candidates were picked. For example, if you reach the last candidate (with still one to pick), the probability for that one will be 100%.
Luc Pattyn wrote: So you are cheating a bit
to make it work all the time, at the expense of the first elements in the array,
since your probabilities are increasing at first.
Not at all. There is no cheating at all, the randomness is completely accurate.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Sorry, my mistake. I did a little example earlier (5 out of 10), but went wrong early on, so it looked
as if probabilities were increasing with i. But they are not, everything was fine when I tried it once
more. This is a fantastic little algorithm, and I hadn't seen it before. Thanks.
|
|
|
|
|
That's one to remember. And I suppose an Excel macro could be written to implement it.
|
|
|
|
|
Hello Friends,
I want to know how can we share desktop. I know this is very hard to do all the things,
but here i am asking for any demo example from which i can learn more.
Thanks in Advance.
Best Regards,
Chetan Patel
|
|
|
|
|
|
I am looking for a collection that is typesafe and will allow me to add two items.
eg:
NewCollection<Type, Color>> collection = new NewCollection<Type, Color>>();
collection.Add(theType, theColor);
I've had a look on MSDN, and the only collections that accept two values are key, value (i.e: hashtables). The problem with this is i want to be able to get the values by index.
eg:
Type typeReturned = collection.ValueType[32];
Color colorReturned = collection.ValueColor[32];
OrderedDictionary would be fine if it was typesafe. So does anyone know of a collection that matchs my needs?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Hi Gareth,
I did not know OrderedDictionary.
the one you want maybe is called SortedList.
In this world a Dictionary is not sorted at all, and a SortedList looks like a real dictionary!
Some collections have a static Synchronized method, for the ones that don't you can provide it
easily yourself.
|
|
|
|
|
|
Can't you create a wrapper class that stores the two items? A simple (built-in) method would be something like:
var collection = new List<KeyValuePair<Type, Color>>();
collection.Add(new KeyValuePair<Type, Color>(theType, theColor));
Type typeReturned = collection[32].Key;
Color colorReturned = collection[32].Value; If you created your own wrapper class then you'll be able to add as menu "sub-items" as you want and give them proper names, but I've used the KeyValuePair in the past when I've wanted something quick and dirty.
|
|
|
|
|
Ed.Poore,
Cheers, i did not think of that.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Hi,
I have developed a web-service.It has some dll's written in windows apps using c#.net. My webservice is working fine on my local system.(I gave webservice IP as "http://mysystemIP/../xxxxx.asmx".)using another windows apps I added web refrence and working fine in my local system
Now I want make my webservice work on another system and to access all the webmethods.
1.If the systems are in LAN,how to do that work?
2.If systems are in WAN,how to do tthat work?
kindly guide me...
|
|
|
|
|
[edit]Don't know why a blank message appeared[/edit]
- Should be alright provided that there are no security restrictions in place between you and the server.
- Provided your host can host it and your client can access the host there will (hopefully) be no problems.
Last modified: after originally posted -- Don't know what happened there
|
|
|
|
|
Hi all,
How can i split a byte array...
I have a byte array whith some data and i want to split that byte array from specified location with specified length.....
something like
byte[] newbyte = bytedata.split(startIndex,Length);
Thanks in advance
Vayanan
|
|
|
|
|
This thread[^] 9 days ago has a few answers
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks alot
Regards
Vayanan
|
|
|
|
|
hi,
I developed a web servcie.Now iam using that in windows applications.I have given anonymous access inIIS.even though iam getting the following error
System.Web.Services.Protocols.SoapException: Server was unable to process request. System.UnauthorizedAccessException: Access to the path
|
|
|
|
|
The server is probably denying access to the a file which you're trying to read in the service. See if running it in debug mode (the web service) provides more details as to where in the code for the service the request is being denied.
|
|
|
|
|
hi friends
first can i install mssql server 2000 on linux server????
can i connect and use ms sql server 2000 from windows application(C#) ??
i have application with c# and database with ms sql server 2000 . but manager of this project said me that i have to use linux server instead of current windows server... please guide me to solve this problem.
thank you
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
mssql server cannot be installed on Linux.
If your manager insists to use Linux, you should use cross platform database like MySQL.
|
|
|
|
|
As the previous poster said, use MySQL. They have a .Net connector you can download from their site, install it and add a reference to your project and it's easy from there. No problems connecting to Linux/MySQL from a windows app (C#).
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|