arcgis python 随机数 语法用法一例:
//---------------------------------------------
//定义函数getnums 返回一个随机数(0,5)
def getnums():
return arcgis.rand('Integer 0 5')
调用方法
Expression: getnums()
Expression Type: PYTHON_9.3
--the--end---
————————————————-------------------------------------------------
步骤如下:
1.打开Field Calcualtor
2.点击Python代码选项
3.点击Show Codeblock, 粘贴我的代码:
def fillRandomInt(intMin, intMax):
import random
return random.randint((int(intMin), int(intMax))
4.下面字段赋值窗口粘贴如下代码(1,100可自行修改):
fillRandomInt(1,100)
-----------------------------------------------------------------------------------------
#coding:UTF-8 import time import random import re # 根据时间返回,返回随机年月日时间 def getRandomDate(sYear, sMonth, sDay, eYear, eMonth, eDay): a1=(sYear,sMonth,sDay,0,0,0,0,0,0) a2=(eYear,eMonth,eDay,23,59,59,0,0,0) start=time.mktime(a1) end=time.mktime(a2) t=random.randint(start,end) date_touple=time.localtime(t) date=time.strftime("%Y/%m/%d",date_touple) return date
调用:getRandomDate(2010,1,1,2019,1,1)