I'm writing a little program recently , You need to get a string of the specified length  number float time Data of the same type , So I encapsulate a function

# Generates a string of the specified length def random_char(length,flag):#flag by 0 express number,1 Represents a string type ,2 express time type
result = '' chars =
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789' nums =
'123456789' numlength = len(nums) - 1 charlength = len(chars) - 1 str_tmp =
Random() if flag == 1: result = datetime.datetime.now().strftime("%Y-%m-%d
%H:%M:%S") return result elif flag == 2: result =
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f") return result elif
flag == 3 or flag == 4: for i in range(int(length)): if flag == 3:
#1 express date,2 express timestamp,3 express number,4 express varchar2 nvarchar2 long char,5 express float result
+= nums[str_tmp.randint(0,numlength)] elif flag == 4: result +=
chars[str_tmp.randint(0,charlength)] elif flag == 5:#length == P20S8 Namely PRECISION
= 20 SCALE = 8 precision,scale = get_precision_scale(length) integer_max =
int(precision) - int(scale) for j in range(integer_max): result +=
nums[str_tmp.randint(0,numlength)] result += '.' for k in range(int(scale)):
result += nums[str_tmp.randint(0,numlength)] return result

Technology
©2019-2020 Toolsou All rights reserved,
QT Delete directory and file Java aggregate ------LinkedHashMap Underlying principle I've been drinking soft water for three years ? What is the use of soft water and water softener Java Xiao Ming A+B About wechat payment body( Product description ) Problems encountered Digital rolling lottery program 3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! Huawei Mate 40 Pro+ 5G exposure : Leica film lens , Ceramic body What's the difference in server prices ? Operators Website visitors' mobile phone number capture