Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Programming for raffle stubs

Status
Not open for further replies.

Balarao

MIS
Jun 9, 2003
25
PH
Hello Everybody,

I am still making my random program but this time my ticket stubs is also at random. i.e. I have a ticket numbered:

4000 - 4032
4075 - 4078
4135 - 4205
4313 - 4333
and so on...

Can I make a clipper program to handle random selection of winners using only tickets numbers like the once enumerated above?

Should I maintain a database of these numbers? If so, how could I make the random program pick the winning number?

I made a routine using DO WHILE loop to skip each record in the database, the problem is there's no wait state in my loop so I can't get it to pick a winning number. Is there a command that can interrupt a loop NOT in it's wait state?

Thank you so much for your help.

God bless,
Balarao
 
Put this in the loop, the loop will exit when you hit the ENTER key.


IF INKEY()=13
WINNING_NO = TICKET_NO
EXIT
ENDIF
 
Balarao,
Try the routine described below.
You will need CA Tools III for the random() function
I hope this helps.

Good Luck.
Birol Betoncu.


private ticary:={}
aadd(ticary,{4000,4032})
aadd(ticary,{4075,4078})
aadd(ticary,{4135,4205})
aadd(ticary,{4313,4333})

x=0
do while x<>27 && exit when esc key pressed
n=len(ticary)
k=(random() % n) + 1 && gives a number 1..n
j=ticary[k,2]-ticary[k,1]+1
m=(random() % j) && gives a number 0..j-1
tic_num=m+ticary[k,1]
? trans(tic_num,'9999')
x=inkey(0)
enddo


 
Dear Acerrudo,

This won't work as there is no wait state inside the loop to read the INKEY() Command.

Dear Betoncu,

Yes, it will work but I don't have CA Tools III.

What I did was to use the snippet below sent to me by one of our generous colleague:

STATIC FUNCTION Randomize( nMax )
* Generates random number

LOCAL nSeed, m := 100000000, b := 31415621

nSeed := IIF( nSeed == NIL, seconds(), nSeed ) // init_seed()

RETURN( nMax * ( ( nSeed := mod( nSeed*b+1, m ) ) / m ) )

I first generate a random number and use it's result as a record skipping counter in my DO WHILE loop.

Thank you, Acerrudo, Betoncu, for your time and generosity in extending a helping hand...

God Bless,

Balarao
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top