The final input of my work will be quintile ee.Image objects. To test my display I would like to create an ee.Image with the value in each pixel set randomly in [1, 5] (only integer).

I have already an ee.Image that could be used as a base:

var data = ee.Image('Oxford/MAP/accessibility_to_cities_2015_v1_0')

I just want to rewrite every pixel in it.

Is there a simple way to do that in Google Earth Engine ?

1 Answer 1


You can create a random image with ee.Image.random(). It will be between 0 and 1. To convert it to ints between 1 and 5, you can do this:


If you want to use the same mask as your data image, you can do this:

var image = ee.Image.random().multiply(5).add(1).byte()


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.