# Speed up code Ideas Please

**URL:** <https://forum.wixstudio.com/t/speed-up-code-ideas-please/14287>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [January 9, 2019, 2:08pm UTC](https://forum.wixstudio.com/t/speed-up-code-ideas-please/14287 "2019-01-09T14:08:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mafinthedales](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mafinthedales/32/7620_2.png) [@mafinthedales](https://forum.wixstudio.com/u/mafinthedales)\
**Post date:** [January 9, 2019, 2:08pm UTC](https://forum.wixstudio.com/t/speed-up-code-ideas-please/14287/1 "2019-01-09T14:08:55Z")

</div>

Basically picking 3 random images from a collection… How to make it quicker ?

export function button1\_click(event) {  
wixData.query(“Images”)  
.find()  
.then( (results) =\> {  
let randomNumber1 = Math.floor((Math.random() \* results.items.length));  
let randomItem1 = results.items[randomNumber1];  
$w(“#image1”).src = randomItem1.image;  
console.log(randomItem1);  
let randomNumber2 = Math.floor((Math.random() \* results.items.length));  
let randomItem2 = results.items[randomNumber2];  
$w(“#image2”).src = randomItem2.image;  
console.log(randomItem2);  
let randomNumber3 = Math.floor((Math.random() \* results.items.length));  
let randomItem3 = results.items[randomNumber3];  
$w(“#image3”).src = randomItem3.image;  
console.log(randomItem3);  
});  
}

---

<div class="post-metadata">

**Author:** ![mafinthedales](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mafinthedales/32/7620_2.png) [@mafinthedales](https://forum.wixstudio.com/u/mafinthedales)\
**Post date:** [January 10, 2019, 9:14am UTC](https://forum.wixstudio.com/t/speed-up-code-ideas-please/14287/2 "2019-01-10T09:14:45Z")

</div>

I started thinking about caching the collection, then got to thinking that if I preload them into a hidden gallery and then randomize from the gallery ? What do you think ?
