Вероятно, есть способ сделать это и в MS Access, но я не могу его запуститьЭто решение будет работать с любой базой данных.
<cfscript>
/* equivalent to SELECT id,name,weight FROM images ORDER BY name */
images = queryNew("id,name,weight", "integer,varchar,integer");
for (i=1; i<=4; i++) {
queryAddRow(images);
querySetCell(images, "id", i);
querySetCell(images, "name", "Image #i#");
}
querySetCell(images, "weight", 20, 1);
querySetCell(images, "weight", 30, 2);
querySetCell(images, "weight", 50, 3);
querySetCell(images, "weight", 100, 4);
</cfscript>
<cfset totalScore = 0>
<cfset scores = []>
<cfloop query="images">
<cfset totalScore += weight>
<cfset arrayAppend(scores, totalScore)>
</cfloop>
<cfset selectionScore = randRange(1,totalScore)>
<cfloop from="1" to="#arrayLen(scores)#" index="rowNumber">
<cfset score = scores[rowNumber]>
<cfif selectionScore LTE score>
<cfbreak/>
</cfif>
</cfloop>
<cfoutput>
#selectionScore#<br />
#images.id[rowNumber]#<br />
#images.name[rowNumber]#<br />
#images.weight[rowNumber]#
</cfoutput>