I don't know why you are doing raw sql but here's a way you could do it using Django queries...
def sample_results(request):
try:
perc = float(request.GET['percent'])
except AttributeError:
# Default to showing all records
perc = 100
# Decimal version of percent
perc = perc / 100
# get all objects in a random order
results = SomeModel.objects.all().order_by("?")
#determine how many to grab from the queryset
num = results.count()
grab = int(num * perc)
# refine the results to the first however many we need
results = results[:grab]
return render_to_response("some/template.html", {"results": results}, context_instance=RequestContext(request))
Thus, if you had /some/url?percent=40 this would show 40% of all the objects of a model, randomized.
from random import sample, no?