The randomizer API is a collection of random item generators that can be used for various logical or random decision making applications.
Contents
1. Object Properties
The randomizer API will output a JSON object with various properties depending on the selected operating mode. See each section below for examples.
2. Operating Modes
There are several API modes depending on the type of data you want to retrieve.
i. Simple Random Numbers
https://api.viewbits.com/v1/randomizer?mode=simple
Use this call to return simple random numbers with timestamp. You can control the output and return a maximum of 6 items with the following parameters:
User Input | Description |
qty* | Number of random items to return. Default: 1. Max: 6. |
min | Random number minimum value. Default: 0. |
max | Random number maximum value. Default: 100. |
The API will output a JSON object with the following properties:
Property | Description |
timestamp | Creation date in UNIX timestamp format. |
data | Array of random numbers based on input parameters. |
result | Total of all random numbers in data array. |
Examples:
1. Return a simple random number:
https://api.viewbits.com/v1/randomizer?mode=simple
{"timestamp":1708006516,"data":[39],"result":39}
2. Return a random number between 100 and 1000:
https://api.viewbits.com/v1/randomizer?mode=simple&min=100&max=1000
{"timestamp":1708006801,"data":[765],"result":765}
3. Return 4 random numbers between 500 and 10000:
https://api.viewbits.com/v1/randomizer?mode=simple&min=100&max=1000&qty=4&key=[YOUR_KEY]
{"timestamp":1708006930,"data":[6892,9954,608,6860],"result":24314}
ii. Flip Coin
https://api.viewbits.com/v1/randomizer?mode=flipcoin
Use this call to replicate a coin flip. You can return up to 6 flips and get a result based on the most number of flips.
User Input | Description |
qty* | Number of coin flips to return. Default: 1. Max: 6. |
The result is a JSON object with the following properties:
Property | Description |
timestamp | Creation date in UNIX timestamp format. |
data | Array of random coin flips. |
headsCount | Number of head results. |
tailsCount | Number of tails results. |
result | Winner based on number of results. |
Examples:
1. Return a single coin flip:
https://api.viewbits.com/v1/randomizer?mode=flipcoin
{"timestamp":1708010777,"data":["Heads"],"headsCount":1,"tailsCount":0,"result":"Heads"}
2. Return 3 coin flips and get the best 2 out of 3:
https://api.viewbits.com/v1/randomizer?mode=flipcoin&qty=3&key=[YOUR_KEY]
{"timestamp":1708007399,"data":["Tails","Heads","Tails"],"headsCount":1,"tailsCount":2,"result":"Tails"}
iii. Roll Dice
https://api.viewbits.com/v1/randomizer?mode=rolldice
Use this call to replicate rolling dice. You can return up to 6 rolls and get a total.
User Input | Description |
qty* | Number of dice to roll. Default: 1. Max: 6. |
The result is a JSON object with the following properties:
Property | Description |
timestamp | Creation date in UNIX timestamp format. |
data | Array of dice rolls. |
result | Total number of all rolls. |
Examples:
Return a single dice roll:
https://api.viewbits.com/v1/randomizer?mode=rolldice
{"timestamp":1708008637,"data":[3],"result":3}
Roll three dice:
https://api.viewbits.com/v1/randomizer?mode=rolldice&qty=3&key=[YOUR_KEY]
{"timestamp":1708008709,"data":[4,4,5],"result":13}
iv. Rock, Paper, Scissors
https://api.viewbits.com/v1/randomizer?mode=rps
Use this call to replicate a game of Rock, Paper, Scissors.
User Input | Description |
move | User move (r = rock, p = paper, s = scissors). Default = r. |
The result is a JSON object with the following properties:
Property | Description |
timestamp | Creation date in UNIX timestamp format. |
userMove | User’s move. |
compMove | Computer’s move. |
result | Game result. |
Example
https://api.viewbits.com/v1/randomizer?mode=rps&move=p
{"timestamp":1708008840,"userMove":"Paper","compMove":"Rock","result":"You win!"}
3. Use Limits
When no API key is provided, calls are limited to 5 per 30 second period. To increase rate limits and disable CORS, you must provide an API key by adding &key=[YOUR_KEY] to the end of your call.
Example: https://api.viewbits.com/v1/randomizer?mode=[SELECTION]&key=[YOUR_KEY]