| | |
| | | rate = random.randint(1, randList[-1][0])
|
| | | return GetResultByRiseList(randList, rate)
|
| | |
|
| | | ## 获得对应数位的值
|
| | | # @param numValue 数值
|
| | | # @param dataIndex 数位索引
|
| | | # @return 获得的值 |
| | | def GetDataByDigitPlace(numValue, dataIndex):
|
| | | return (numValue/pow(10, dataIndex))%10
|
| | | |
| | |
|
| | | ## 设置对应数位的值
|
| | | # @param numValue 数值
|
| | | # @param dataIndex 数位索引
|
| | | # @param dataValue 当前修改数值
|
| | | # @return 获得的值 |
| | | def ChangeDataByDigitPlace(numValue, dataIndex, dataValue):
|
| | | |
| | | if dataValue < 0 or dataValue > 9 or dataIndex > ShareDefine.Def_PDictDigitCnt:
|
| | | return numValue
|
| | | |
| | | # 获得对应数位的值
|
| | | lastTagLV = GetDataByDigitPlace(numValue, dataIndex)
|
| | | |
| | | numValue += pow(10, dataIndex)*(dataValue - lastTagLV)
|
| | | return numValue
|
| | |
|
| | | def GetBitValue(dataValue, index):
|
| | | """ 得到某个字节值中某一位(Bit)的值
|
| | | @param dataValue: 待取值的字节值
|
| | | @param index: 待读取位的序号,从右向左0开始,0-7为一个完整字节的8个位
|
| | | @return: 返回读取该位的值,0或1
|
| | | """
|
| | | return 1 if dataValue & (1 << index) else 0
|
| | |
|
| | | def SetBitValue(dataValue, index, val):
|
| | | """ 更改某个字节值中某一位(Bit)的值
|
| | | @param dataValue: 准备更改的字节原值
|
| | | @param index: 待更改位的序号,从右向左0开始,0-7为一个完整字节的8个位
|
| | | @param val: 目标位预更改的值,0或1
|
| | | @return: 返回更改后字节的值
|
| | | """
|
| | | if val:
|
| | | return dataValue | (1 << index)
|
| | | return dataValue & ~(1 << index)
|
| | |
|
| | | ## 根据字典key获取value值
|
| | | # @return
|
| | | def GetDictValueByKey(attrDict, findKey, defaultValue=None):
|