Need to generate lottery numbers in your application? This guide covers everything you need to know about lottery number generation via API, including different lottery formats, bonus balls, and implementation examples.
Lottery Formats
Different lotteries use different formats for their number selections. Most involve picking unique numbers from a range, sometimes with additional "bonus" or "powerball" numbers from a separate range.
The API supports configurable formats to match any lottery system worldwide.
True Randomness
Popular lottery formats and their configurations:
Powerball (US)
5 numbers from 1-69, plus 1 Powerball from 1-26. One of the most popular US lotteries.
Mega Millions (US)
5 numbers from 1-70, plus 1 Mega Ball from 1-25.
EuroMillions
5 numbers from 1-50, plus 2 Lucky Stars from 1-12.
6/49 Format
6 numbers from 1-49. Used in many national lotteries (UK, Canada, Germany).
Using the Lottery Number API
TinyFn provides a simple endpoint to generate lottery numbers:
GET https://api.tinyfn.io/v1/random/lottery?main_count=5&main_max=69&bonus_count=1&bonus_max=26
Headers: X-API-Key: your-api-key
{
"main_numbers": [7, 23, 34, 45, 62],
"bonus_numbers": [15],
"formatted": "7 - 23 - 34 - 45 - 62 | PB: 15",
"config": {
"main_count": 5,
"main_range": [1, 69],
"bonus_count": 1,
"bonus_range": [1, 26]
}
}
Parameters
| Parameter | Type | Description |
|---|---|---|
main_count |
integer | How many main numbers to pick |
main_max |
integer | Maximum value for main numbers |
bonus_count |
integer | How many bonus numbers (optional) |
bonus_max |
integer | Maximum value for bonus numbers |
preset |
string | Preset: powerball, megamillions, euromillions, 6_49 |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/random/lottery?preset=powerball',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(data.formatted); // 7 - 23 - 34 - 45 - 62 | PB: 15
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/random/lottery',
params={'preset': 'powerball'},
headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(f"Main: {data['main_numbers']}, Bonus: {data['bonus_numbers']}")
cURL
curl "https://api.tinyfn.io/v1/random/lottery?preset=powerball" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Lottery Apps: Quick pick number generators
- Entertainment: Fun random number selection
- Pool/Syndicate Tools: Generate numbers for lottery pools
- Game Development: Lottery mini-games
- Number Analysis: Generate test data for lottery analysis tools
Best Practices
- Sort numbers: Display main numbers in ascending order
- Distinguish bonus: Clearly separate bonus/powerball numbers
- Add disclaimer: Make clear this is for entertainment only
- Support presets: Make common formats easy to use
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-random": {
"url": "https://api.tinyfn.io/mcp/random/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all random tools available via MCP in our Random MCP Tools for AI Agents guide.
Try the Lottery Number API
Get your free API key and start generating lottery numbers in seconds.
Get Free API Key