MCPcopy Index your code
hub / github.com/RustPython/RustPython / main

Function main

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

Source from the content-addressed store, hash-verified

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

Callers 1

random.pyFile · 0.70

Calls 4

lenFunction · 0.85
_parse_argsFunction · 0.70
_testFunction · 0.70
splitMethod · 0.45

Tested by

no test coverage detected