tags:

views:

146

answers:

2

Can you tell me a best script / program that will pull a winner at random.

These are all entrants to a competition and one winner needs to be chosen randomly.

The data in Excel sheet. I want to run the script against excel.

A: 

save as CSV then

in python:

import random
fd = open(csv_file)
lines = fd.readlines()
line_num = random.randrange(0,len(lines)-1)
print 'winner: ', lines[line_num]
SpliFF
+4  A: 

The following assumes your list of entrants is in a range named "Entrants". Naturally, the usual caveats about system-generated random numbers not exactly being random apply - should be fine for local/small scale fun competition, probably not the solution for a national lottery.

Sub PickWinner()
    Dim winner As String

    winner = Range("Entrants").Cells(Int(Rnd() * (Range("Entrants").Count) + 1), 1)

    Debug.Print winner
End Sub
Lunatik