Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to do a random value calculation within a range in QGIS? I have been able to do this within ArcMap Field Calculator with the following code:

Dim max, min



share|improve this question
The built in field calculator doesn't have a "Random" function. This would be relatively easy to do with Python if there's an Advanced Field Calculator plugin (or equivalent) out there somewhere. Anyone? – GIS-Jonathan Apr 26 '12 at 13:47
That is my thoughts. I do the same thing in the ArcMap Field Calculator with the Advanced option. Is there any development for the Field Cal in QGIS in the next release? – Ryan Garnett Apr 27 '12 at 13:47
You'd have to ask on the QGIS mailing list - – GIS-Jonathan Apr 27 '12 at 13:57
up vote 4 down vote accepted

While QGIS doesn't appear to have this functionality, you may be able to work "around" it.

If you export your data to a SpatiaLite database you can then use the random() from SQLite in an SQL statement. I guess something like this:

update TABLE set COLUMN = ROUND((20-5+1) * random() + 5)

Any other database would do too, but that one can be treated as a local file and doesn't require installation of something seperate.

share|improve this answer

QGIS 2.4+ has a couple of random number functions:

rand(min,max) # returns a random integer between min and max, inclusive

randf(min,max) # returns a float value.
share|improve this answer
Yes thank you. I am aware of that change. – Ryan Garnett Jan 28 '15 at 13:19
Yep, just thought I'd add this in case anyone comes searching! – Simbamangu Jan 31 '15 at 5:42

You could load the DBF into OO/Libre Office Calc and do this there. I think you need to have Base installed for Calc to be able to work with DBFs and you'd need to set the headers for columns that you create appropriately for data-type, field width, precision and so on. I quite often work on shapefile DBFs in Calc and have never had problems doing this, it's very convenient.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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