Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I have is an excel spreadsheet that has users First Name, Last Name, and number of times they've answered a daily trivia question correctly for the last month. What I want to do is select a winner based on a raffle system, where the users get one entry for every question they answered correctly. I have a way of doing it in Java, but I'd like to do it in excel if possible. Here is my Java code if it helps explain:

public static void main(String[] args) throws FileNotFoundException {
    File file = new File("TriviaParticipantsList.txt");
    Scanner scanner = new Scanner(file);
    int x = 0;
    int j = 0;
    int i = 0;

        String line = scanner.nextLine();
        Scanner scan = new Scanner(line);

        i = scan.nextInt();
        String name = scan.nextLine();
            //do nothing if no questions were answered
            for(j=0; j<i; j++)
                System.out.print(j+x); //Print out "ticket number"
                System.out.println(" " + name); //Print out owner name of ticket
    System.out.println(x); //Verify correct number of entries
    int winner = (int) (Math.random()*x); //Select random number based on number of entries
    System.out.println(winner); //Display value, look through list to find who number belongs to!

Any help is greatly appreciated!

share|improve this question

I could imagine (as in "i did not try it") that a cumulative sum of the correct answers combined with a lookup on a random number might do the trick.

Name | Correct | Sum
P1        3       3
P2        2       5
P3        4       9

Create a cell with a random number and maybe a button to trigger the recalculation or make it fill the cell with the formula for the random number or something like that.

Then you should be able to do a lookup that returns "P2" for example if you drew number 4. Edit: Check the help on the lookup function how to make it return the correct one, i believe it can do what you desire. Otherwise you might have to work around that with a helper column.

The random number of course has to run from 1 to the maximum of the cumulative sum.

Hope that helps somehow ;-)

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .