128k views
1 vote
What function in the secrets module can generate random integers between one and 14, including the possibility of both one and 14?

secrets.random(14)
secrets.random(14)

secrets.randbelow(14)
secrets.randbelow(14)

secrets.random(15)
secrets.random(15)

secrets.randbelow(15)
secrets.randbelow(15)

User Rhitz
by
8.7k points

1 Answer

7 votes

Final answer:

The secrets.randbelow(15) function generates a random integer between 1 and 14, inclusive. You then add 1 to include the lower bound since the function starts from 0. This function is suitable for secure randomization tasks such as generating unique state numbers.

Step-by-step explanation:

The correct function in the secrets module for generating a random integer between one and 14, inclusive of both 1 and 14, is secrets.randbelow(15). The function secrets.randbelow(n) will return a random integer from 0 up to, but not including, the integer n.

To include 1 as the lowest possible value and 14 as the highest, you must call secrets.randbelow(15) and then add 1 to the result, because the function starts counting at 0. For example, to simulate random states by their numbered positions, you may generate eight numbers without duplicates using secrets.randbelow(51) plus 1 to represent states for an activity.

User Complez
by
7.7k points