# Avoid 'clunky' sketch/framerate

**URL:** https://discourse.processing.org/t/avoid-clunky-sketch-framerate/12041
**Category:** Coding Questions
**Created:** [June 13, 2019, 2:46pm UTC](https://discourse.processing.org/t/avoid-clunky-sketch-framerate/12041 "2019-06-13T14:46:02Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![mcd4u](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@mcd4u](https://discourse.processing.org/u/mcd4u)
#### Post date: [June 13, 2019, 3:01pm UTC](https://discourse.processing.org/t/avoid-clunky-sketch-framerate/12041/5 "2019-06-13T15:01:07Z")

</div>

You should take a look at the [documentation](https://processing.org/reference/HashMap.html) on maps. In this case, I would suggest having the number in your filename as the key, and the actual PImage object as the value. So in `draw()`, you can simply get the image from the map (using `.get(ranNum)`) instead of calling `loadImage()` multiple times.

You won’t be stuck with the same random selection as long as you keep the random number generator code in your `draw()` function. You’re really only changing the `loadImage()` part.

As a side note, since you mentioned that your program will handle up to 100,000 images, loading all of those PImages will cost a lot of memory. One way to solve this is to combine all of those images into 1 big image atlas beforehand so that you end up only loading 1 image. Then you have to figure out a way to get the correct portion of that atlas using the random number.

MCD4U

---

_[View the full topic](https://discourse.processing.org/t/avoid-clunky-sketch-framerate/12041)._
