Need to shuffle text randomly? This guide covers everything you need to know about text shuffling via API, including different shuffle modes and ensuring true randomness.
What is Text Shuffling?
Text shuffling randomly rearranges elements of text - whether lines, words, or characters. This is useful for randomization tasks, creating puzzles, or generating test data. A good shuffle uses cryptographically secure randomness for unpredictable results.
Example: "Apple\nBanana\nCherry" shuffled might become "Cherry\nApple\nBanana"
Shuffle Modes
Different ways to shuffle text:
- Line shuffle: Randomize the order of lines
- Word shuffle: Randomize words within text
- Character shuffle: Randomize individual characters
- Paragraph shuffle: Randomize paragraph order
Using the Text Shuffle API
TinyFn provides a simple endpoint to shuffle text:
POST https://api.tinyfn.io/v1/text/shuffle
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"text": "Apple\nBanana\nCherry\nDate\nElderberry",
"mode": "lines"
}
{
"original": "Apple\nBanana\nCherry\nDate\nElderberry",
"shuffled": "Cherry\nElderberry\nApple\nDate\nBanana",
"mode": "lines",
"element_count": 5
}
Parameters
| Parameter | Type | Description |
|---|---|---|
text |
string | The text to shuffle (required) |
mode |
string | Shuffle mode: lines, words, characters (default: lines) |
seed |
integer | Random seed for reproducible results (optional) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/text/shuffle',
{
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: 'Apple\nBanana\nCherry',
mode: 'lines'
})
}
);
const result = await response.json();
console.log(result.shuffled); // Random order
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/text/shuffle',
headers={'X-API-Key': 'your-api-key'},
json={'text': 'Apple\nBanana\nCherry', 'mode': 'lines'}
)
result = response.json()
print(result['shuffled']) # Random order
cURL
curl -X POST "https://api.tinyfn.io/v1/text/shuffle" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"text": "Apple\nBanana\nCherry", "mode": "lines"}'
Common Use Cases
- Quizzes & Games: Randomize question or answer order
- Playlists: Shuffle song or item lists
- A/B Testing: Randomize test group assignments
- Word Games: Create anagram puzzles
- Test Data: Generate randomized test inputs
Best Practices
- Use seeds for testing: Reproducible shuffles help with debugging
- Choose appropriate mode: Line shuffle for lists, word for sentences
- Handle single items: Shuffling one item returns the same item
- Consider fairness: Use cryptographically secure randomness for contests
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-text": {
"url": "https://api.tinyfn.io/mcp/text/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all text analysis tools available via MCP in our Text Analysis MCP Tools for AI Agents guide.
Try the Text Shuffle API
Get your free API key and start shuffling text in seconds.
Get Free API Key