Announcement : On
November 13, 2024 , all users will need to
use a Cloud project in order to access Earth Engine. After this date, continued individual access without a Cloud project will require
an exception .
Send feedback
ee.FeatureCollection.randomColumn
Stay organized with collections
Save and categorize content based on your preferences.
Adds a column of deterministic pseudorandom numbers to a collection. The outputs are double-precision floating point numbers. When using the 'uniform' distribution (default), outputs are in the range of [0, 1). Using the 'normal' distribution, outputs have μ=0, σ=1, but have no explicit limits.
Usage Returns FeatureCollection. randomColumn (columnName , seed , distribution )
FeatureCollection
Argument Type Details this: collection
FeatureCollection The input collection to which to add a random column. columnName
String, default: "random" The name of the column to add. seed
Long, default: 0 A seed used when generating the random numbers. distribution
String, default: "uniform" The distribution type of random numbers to produce; one of 'uniform' or 'normal'.
Examples
Code Editor (JavaScript)
// FeatureCollection of power plants in Belgium.
var fc = ee . FeatureCollection ( 'WRI / GPPD / power_plants ')
. filter ( 'country_lg == "Belgium "');
print ( 'N features in collection ', fc . size ());
// Add a uniform distribution random value column to the FeatureCollection.
fc = fc . randomColumn ();
// Randomly split the collection into two sets, 30% and 70% of the total.
var randomSample30 = fc . filter ( 'random < 0.3 ');
print ( 'N features in 30 % sample ', randomSample30 . size ());
var randomSample70 = fc . filter ( 'random >= 0.3 ');
print ( 'N features in 70 % sample ', randomSample70 . size ());
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
Colab (Python)
# FeatureCollection of power plants in Belgium.
fc = ee . FeatureCollection ( 'WRI / GPPD / power_plants ') . filter (
'country_lg == "Belgium "')
print ( 'N features in collection :', fc . size () . getInfo ())
# Add a uniform distribution random value column to the FeatureCollection.
fc = fc . randomColumn ()
# Randomly split the collection into two sets, 30% and 70% of the total.
random_sample_30 = fc . filter ( 'random < 0.3 ')
print ( 'N features in 30 % sample :', random_sample_30 . size () . getInfo ())
random_sample_70 = fc . filter ( 'random >= 0.3 ')
print ( 'N features in 70 % sample :', random_sample_70 . size () . getInfo ())
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-13 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
Need to tell us more?
{"lastModified": "Last updated 2024-07-13 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-13 UTC."]]