I have 500 records on parse class or table and now i need to get 10 random records out of 500 records?
Please tell me how can I do this.
ParseQuery
This is working code for fetching random objects from given class in Parse
In cloud code,
Parse.Cloud.define("get10Obj",function(request,response)
{
query = new Parse.Query(request.params.movie);
Array.prototype.randomElement = function (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
query.find ({
success: function(results) {
var final10 = [];
for (var i = 0; i < 5; i++) {
var myRandomElement = results.randomElement(0,results.length);
if (final10.indexOf(myRandomElement) == -1) {
final10.push(myRandomElement);
} else {
i--;
}
}
var datalist =[];
for(var j=0;j
In Android,
HashMap params = new HashMap();
params.put("movie", "The Matrix");
ParseCloud.callFunctionInBackground("averageStars", params, new
FunctionCallback() {
void done(ParseObject ratings, ParseException e) {
if (e == null) {
// Do your stuff
}
}
});
Thanks to st.derrick for biggest hint.