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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a simple lucky draw engine? 1

Status
Not open for further replies.

Chel

Programmer
Aug 1, 2001
16
MY
Hi,
I m very new in programming. I don't have any idea in solving this problem.

I want to create a lucky draw engine. For example: I have 23 names in my table. Now, I want to get randomly 1 person from name-no1 till name-no5. Then, another 1 person from name-no6 till name-no10. (get 1 out of 5 each time). And this engine will still continue whenever we get 5 new ppl (or more) in the same table.

Can anyone give me suggestion in how to do this lucky draw engine? Thank you very much.
 
Cold Fusion has three functions you can use. They are RAND, RANDOMIZE, and RANDRANGE. RANDRANGE returns a random number in a range you specify, so I imagine that is the one you will want to use. But, read the documentation on the others and see if they will help you. Good luck! ;-) Calista :-X
Jedi Knight,
Champion of the Force
 
Dear Calista,
Thank you for your information. That's very kind of you.
I will work it out now. Hopefully I can make it. :-D
 
Dear CFHub,
I have got the code. But I am not too understand with the following coding:

1. <cfset GoodSeed = (Minute(now())&Second(now()))>
<cfset GoodSeed = Randomize(GoodSeed)>
--> 'Minute', 'Second' , 'now' are commands or
variables?


2.SELECT TOP 5 item_id, newid() as new_id
--> what's 'item_id' ?

Thank you~ :-D

 
The following is my coding. I don't know what's wrong with it. Error occurred within the looping.
Can anyone help me again????

My coding:
<cfquery name=&quot;randomDraw&quot; datasource=&quot;LD&quot;>
SELECT *
FROM luckydraw
WHERE status IS NULL
</cfquery>

<cfif #randomDraw.recordcount# GT 0>
<cfquery datasource=&quot;LD&quot; name=&quot;cnt&quot;>
SELECT max(new_id) as maxID,
min(new_id) as minID
FROM luckydraw
</cfquery>
</cfif>

<cfquery name=&quot;refGroup&quot; datasource=&quot;LD&quot;>
SELECT *
FROM referGP
WHERE fieldname like 'rewardgp'
</cfquery>

<!--- #refGroup.percentage#=5 in table:ref --->
<!--- so that we can change '5' to other number --->
<!--- we want in the future --->

<cfset y = #refGroup.percentage#>

<!--- only want 5 in 1 group --->
<!--- if max(new_id)=23, the mod will be 3. --->
<!--- so,this 3 ids have to wait till they get another---> <!--- 2 more ids in table:luckydraw--->
<!--- in order to take part in the new lucky --->
<!--- draw session --->
<cfset x = #int((#cnt.maxID# - #cnt.minID# + 1) / #y#)#>

<cfloop index=&quot;drawNumber&quot; from=0 to=#x#>

<cfset randomNumber=RandRange((#y#*#x#)+1,(#y#*#x#)+#y#)>
<!--- formula :(5m+1, 5m+5) will count 1-5, 6-10, --->

<cfquery name=&quot;updateA&quot; datasource=&quot;LD&quot;>
UPDATE luckydraw
SET status = &quot;A&quot;
WHERE new_id IS #randomNumber#
</cfquery>

<cfquery name=&quot;updateB&quot; datasource=&quot;LD&quot;>
UPDATE luckydraw
SET status = &quot;B&quot;
WHERE new_id IS NOT #randomNumber#
</cfquery>
</cfloop>

Thank you

Chel :-(
 
These are CF functions:
--> 'Minute', 'Second' , 'now' are

You should find a list of them (with examples) here:



Here, &quot;Item_ID&quot; is &quot;whatever&quot; the name of your tables key is. I can't make it out from your query, but it may simply be &quot;ID&quot;? This will only work on MS SQL (is that what you are using?)

SELECT TOP 5 item_id, newid() as new_id
--> what's 'item_id' ?
 
Dear cfhub,
SELECT TOP 5 item_id, newid() as new_id

About the TOP 5..
Can I change '5' into Variable so that I can change it manually using a form format whenever I want??

Thank you :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top