Register
It is currently Sun Dec 21, 2014 7:39 pm

random number raffle script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Thu Nov 29, 2007 8:19 pm   

Joined: Thu Nov 29, 2007 8:03 pm
Posts: 1
Hi guys and/or gals, hope someone can help me out. here's what I'm looking to do..

need a script that will take input of 'name' 'number of tickets' 'size of ticket numbers'

I was planning on using 'cat /dev/urandom | tr -cd 0-9 | fold -w#' to generate the ticket numbers

I'd like to write to two files

first file setup like:

name;ticketnumber;ticketnumber;etc;
and also echo that line..

second file that just holds the ticketnumbers:

134532
446525
235564
etc..


now each number that the script gets needs to be checked against the second file to make sure that its not already a used number

then would like to be able to finish the raffle by taking the second file, 'shuffling' the lines of the file, and randomly picking one of the lines

if someone could write this up for me, I'd be very greatful.. or at least get me started, I'm very rusty on my bash scripting and not even sure how to start.

Thanks in advance

-kjester


Top
 Profile  
 PostPosted: Fri Dec 07, 2007 5:20 pm   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Here's a random lunch chooser I whipped up as a joke a few weeks ago. It might get you started :)

Code:
#!/bin/bash

rnumber=$((RANDOM%17))
case $rnumber in
  0) echo "Chuy's" ;;
  1) echo "Ninfa's" ;;
  2) echo "Pete's" ;;
  3) echo "Hin's Garden" ;;
  4) echo "Joel's MOM's!!!111oneoneeleventyoneone" ;;
  5) echo "Chipotle" ;;
  6) echo "Freebird's" ;;
  7) echo "McDonald's" ;;
  8) echo "Antone's" ;;
  9) echo "Jack-in-the-Box" ;;
10) echo "Cafe Express" ;;
11) echo "Indian food (Westheimer and Bering)" ;;
12) echo "Lebanese - Cafe Lilly" ;;
13) echo "Thai place" ;;
14) echo "C.H.Burger" ;;
15) echo "Starbucks! (Is coffee a food?)" ;;
16) echo "BW3's - HAHA! J/K, it's closed!" ;;
esac

exit 0


This shows you how you can use the built-in random number stuff in bash, but not much else :) I might take a shot at what you're actually looking for when I get home later.

-J


Top
 Profile YIM  
 PostPosted: Fri Dec 07, 2007 5:25 pm   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Also, here's a good guide on generating with random #'s

http://tldp.org/LDP/abs/html/randomvar.html#EX21

I like your method too :)


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP