Random Selection of Attributes

2792
7
Jump to solution
07-18-2017 06:20 AM
KarunaPaudel
New Contributor

I would like to know how to randomly select certain values from the attribute table.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

A good discussion along with several good code examples can be found in previous threads, including https://community.esri.com/thread/121745 .

View solution in original post

7 Replies
MitchHolley1
MVP Regular Contributor

You can use the random module.  Do you need random values in an attribute table?  Or random rows?

KarunaPaudel
New Contributor

I need to use it from python and not from ArcMap. Also, I just need to select the attributes and not assign random numbers to it.

0 Kudos
MitchHolley1
MVP Regular Contributor

The random module is a Python module.... Do you need to select random attributes from a single field?  All fields? Some fields?  

Please expand on your question.  Give an example. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

Ahhh, then generate your random integers, and use those in a search cursor to extract the values you need

0 Kudos
DanPatterson_Retired
MVP Emeritus

Add a field to your table

Do a field calculation as described here

or you can substitute random.randint in place of random.random if you want integers.

a = random.randint(1, 100)

a
96

or even draw from a uniform distribution

u = int(random.uniform(0, 100))
u
54

or other types of distributions depending on your needs

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

A good discussion along with several good code examples can be found in previous threads, including https://community.esri.com/thread/121745 .

KarunaPaudel
New Contributor

Thank you so much. This seems to work for me.

0 Kudos