RandomNumberGenerator (arcpy)

摘要

确定类型和种子,它们将用于所有使用随机数的工具(例如,CreateRandomRaster、CreateRandomPoints 和 ArcGIS.Rand() 函数)创建 0 到 1 之间的随机数。

已从 randomGenerator 环境返回。

方法概述

方法说明
exportToString ()

Exports the object to its string representation.

loadFromString (string)

Restore the object using its string representation. The exportToString method can be used to create a string representation.

方法

exportToString ()
返回值
数据类型说明
String

The string representation of the object.

loadFromString (string)
参数说明数据类型
string

The string representation of the object.

String

代码实例

RandomNumberGenerator 示例

演示如何创建随机数生成器对象。

import arcpy

# Cannot create RandomNumberGenerator object directly,
# but is returned from CreateRandomValueGenerator function.
#
# CreateRandomValueGenerator takes 2 arguments, seed and distribution
# method. The distribution method options are ACM599,
# MERSENNE_TWISTER, STANDARD_C.
#
# The gen variable is a randomNumberGenerator object that is assigned
# to the randomGenerator environments setting.
#
arcpy.env.randomGenerator = arcpy.CreateRandomValueGenerator(20, "STANDARD_C")

# Calculate a random number using the arcgis.rand() function
result = arcpy.CalculateValue_management("arcgis.rand('normal 0.0 10.0')")

# Get the value from the result object and print it to the Python window.
val = float(result.getOutput(0))
print(val)

相关主题

5/10/2014