Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Using search and update cursors for random number generation

$
0
0

I am having some trouble getting a searchcursor to return a value for each record. The purpose of my code is to scan through a list of records in a field (FieldA) and based on those values populate a second field (FieldB) with a random number between 1 and the value in FieldA. FieldA contains numeric values which vary depending on their association. My code is as follows:

CursorA = arcpy.SearchCursor(FC)
for row in cursorA:
    rowcount =(row.getValue("FieldA"))
    row = cursorA.next()
    cursorB = arcpy.UpdateCursor(FC, "FieldB") 
    for rowB in cursorB:
        rowB[0] = randint(1, rowcount)
        cursorB.updateRow(rowB)

When I run the code it appears as though the searchcursor locates the value of the last record in FieldA and uses that value as the highest value in the random sequence. I could be wrong on this however, and it could be related to improper coding on my part. Any insight is greatly appreciated.


Viewing all articles
Browse latest Browse all 767

Trending Articles