random is now really rendom
This commit is contained in:
@@ -31,28 +31,11 @@ var RandomItems = React.createClass({
|
|||||||
getRandomItems: function() {
|
getRandomItems: function() {
|
||||||
var NUMBER_OF_SUGGESTED_ITEMS = 8;
|
var NUMBER_OF_SUGGESTED_ITEMS = 8;
|
||||||
var allItems = ItemStore.getItems();
|
var allItems = ItemStore.getItems();
|
||||||
var randomIndexStart = Math.floor(Math.random() * ((allItems.models.length - NUMBER_OF_SUGGESTED_ITEMS + 1)));
|
allItems.reset(allItems.shuffle(), {silent:true});
|
||||||
allItems.models = this.shuffle(allItems.models).slice(randomIndexStart, randomIndexStart + NUMBER_OF_SUGGESTED_ITEMS);
|
allItems.reset(allItems.first(NUMBER_OF_SUGGESTED_ITEMS), {silent:true});
|
||||||
return allItems;
|
return allItems;
|
||||||
},
|
},
|
||||||
|
|
||||||
shuffle: function(array) {
|
|
||||||
var currentIndex = array.length, temporaryValue, randomIndex ;
|
|
||||||
|
|
||||||
// While there remain elements to shuffle...
|
|
||||||
while (0 !== currentIndex) {
|
|
||||||
// Pick a remaining element...
|
|
||||||
randomIndex = Math.floor(Math.random() * currentIndex);
|
|
||||||
currentIndex -= 1;
|
|
||||||
// And swap it with the current element.
|
|
||||||
temporaryValue = array[currentIndex];
|
|
||||||
array[currentIndex] = array[randomIndex];
|
|
||||||
array[randomIndex] = temporaryValue;
|
|
||||||
}
|
|
||||||
return array;
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
_onChange: function () {
|
_onChange: function () {
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user