MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Lib/random.py:1039–1075  ·  view source on GitHub ↗
(arg_list: list[str] | None = None)

Source from the content-addressed store, hash-verified

1037
1038
1039def main(arg_list: list[str] | None = None) -> int | str:
1040 args, help_text = _parse_args(arg_list)
1041
1042 # Explicit arguments
1043 if args.choice:
1044 return choice(args.choice)
1045
1046 if args.integer is not None:
1047 return randint(1, args.integer)
1048
1049 if args.float is not None:
1050 return uniform(0, args.float)
1051
1052 if args.test:
1053 _test(args.test)
1054 return ""
1055
1056 # No explicit argument, select based on input
1057 if len(args.input) == 1:
1058 val = args.input[0]
1059 try:
1060 # Is it an integer?
1061 val = int(val)
1062 return randint(1, val)
1063 except ValueError:
1064 try:
1065 # Is it a float?
1066 val = float(val)
1067 return uniform(0, val)
1068 except ValueError:
1069 # Split in case of space-separated string: "a b c"
1070 return choice(val.split())
1071
1072 if len(args.input) >= 2:
1073 return choice(args.input)
1074
1075 return help_text
1076
1077
1078if __name__ == '__main__':

Callers 1

random.pyFile · 0.70

Calls 5

choiceFunction · 0.85
randintFunction · 0.85
_parse_argsFunction · 0.70
_testFunction · 0.70
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…