Calculate the number of attempts needed to achieve target probabilities for events with given odds
The Odds Calculator API helps you determine how many attempts (tickets, tries, etc.) are required to achieve specific probability thresholds of success for events with known odds. Given odds of "1 in N", the API calculates how many attempts you need to have a 50%, 80%, and 95% chance of at least one success.
https://www.promptbox.cn/api/odds.php
| Header | Value | Required |
|---|---|---|
Content-Type |
application/json |
Yes |
| Parameter | Type | Description | Required |
|---|---|---|---|
odds |
number | The odds ratio (N in "1 in N"). Must be a positive number. Example: for 1 in 1,000 odds, use 1000. | Yes |
{
"odds": 1000
}
Returns the number of attempts needed for each probability threshold.
| Field | Type | Description |
|---|---|---|
odds_one_in |
number | The odds ratio that was used in the calculation (rounded to nearest integer) |
attempts_for_50_percent |
integer | Number of attempts needed for a 50% probability of at least one success |
attempts_for_80_percent |
integer | Number of attempts needed for an 80% probability of at least one success |
attempts_for_95_percent |
integer | Number of attempts needed for a 95% probability of at least one success |
{
"odds_one_in": 1000,
"attempts_for_50_percent": 693,
"attempts_for_80_percent": 1609,
"attempts_for_95_percent": 2996
}
Returns an error message when the request is invalid.
| Field | Type | Description |
|---|---|---|
error |
string | Description of what went wrong |
{
"error": "Missing or invalid numeric parameter: 'odds'."
}
{
"error": "Odds must be a positive number."
}
{
"error": "Invalid or empty JSON input."
}
The API uses probability theory to calculate the required number of attempts. For an event with probability p = 1/N of success on each attempt:
n attempts is: (1 - p)^n1 - (1 - p)^nThe API iteratively calculates the minimum number of attempts n where the probability of at least one success meets or exceeds each threshold (50%, 80%, 95%).
fetch('https://www.promptbox.cn/api/odds.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
odds: 1000
})
})
.then(response => response.json())
.then(data => {
console.log('For 50% chance:', data.attempts_for_50_percent, 'attempts');
console.log('For 80% chance:', data.attempts_for_80_percent, 'attempts');
console.log('For 95% chance:', data.attempts_for_95_percent, 'attempts');
})
.catch(error => console.error('Error:', error));
import requests
import json
url = 'https://www.promptbox.cn/api/odds.php'
data = {'odds': 1000}
response = requests.post(url, json=data)
result = response.json()
if response.status_code == 200:
print(f"For 50% chance: {result['attempts_for_50_percent']} attempts")
print(f"For 80% chance: {result['attempts_for_80_percent']} attempts")
print(f"For 95% chance: {result['attempts_for_95_percent']} attempts")
else:
print(f"Error: {result['error']}")
curl -X POST https://www.promptbox.cn/api/odds.php \
-H "Content-Type: application/json" \
-d '{"odds": 1000}'
<?php
$url = 'https://www.promptbox.cn/api/odds.php';
$data = ['odds' => 1000];
$options = [
'http' => [
'header' => "Content-Type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$result = json_decode($response, true);
if (isset($result['attempts_for_50_percent'])) {
echo "For 50% chance: {$result['attempts_for_50_percent']} attempts\n";
echo "For 80% chance: {$result['attempts_for_80_percent']} attempts\n";
echo "For 95% chance: {$result['attempts_for_95_percent']} attempts\n";
} else {
echo "Error: {$result['error']}\n";
}
?>
For questions, issues, or feature requests regarding this API: