Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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;

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

        i = scan.nextInt();
        String name = scan.nextLine();
        if(line.charAt(0)==0)
        {
            //do nothing if no questions were answered
        }
        else
        {
            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
            }
        }
        x=x+i;
    }
    scanner.close();
    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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.