Bug report #11231
Function rand() only gives values up to ~32000
|Affected QGIS version:||master||Regression?:||No|
|Operating System:||Windows 7, 64 bit||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:||end of life|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||19539|
On a spatialite layer, creating a new field with the field calculator and the expression "rand( 100000, 5000000 )" gives values of 100000 - 140000.
This seems not to be a problem on linux.
"randf()" also works properly.
The data type of the field was Integer.
QGIS was installed as 32bit.
#2 Updated by Matthias Kuhn over 5 years ago
Investigating a bit:
Visual Studio (up to 2013) has RAND_MAX defined as 0x7fff: 32767. Author's note: which seems quite stupid on a 32bit/64bit system.
A possibility to overcome this is to call rand() twice and bitshift/combine the values:
Or to use the <random> header file which is part of C++ 2011 and boost
#4 Updated by Giovanni Manghi about 1 year ago
- Resolution set to end of life
- Status changed from Open to Closed
End of life notice: QGIS 2.18 LTR