Skip to content

Instantly share code, notes, and snippets.

@artpar
Created August 16, 2025 11:17
Show Gist options
  • Select an option

  • Save artpar/211ecf0cd52b0f14fd0764d823703786 to your computer and use it in GitHub Desktop.

Select an option

Save artpar/211ecf0cd52b0f14fd0764d823703786 to your computer and use it in GitHub Desktop.
Random JavaScript code with data generators and quotes
// Random JavaScript Code Example
function generateRandomData() {
const colors = ['red', 'blue', 'green', 'yellow', 'purple', 'orange'];
const animals = ['cat', 'dog', 'elephant', 'tiger', 'rabbit', 'dolphin'];
const numbers = Array.from({length: 10}, () => Math.floor(Math.random() * 100));
return {
randomColor: colors[Math.floor(Math.random() * colors.length)],
randomAnimal: animals[Math.floor(Math.random() * animals.length)],
randomNumber: numbers[Math.floor(Math.random() * numbers.length)],
timestamp: new Date().toISOString(),
uuid: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
})
};
}
// Generate some random data
console.log('Random Data Sample:');
for (let i = 0; i < 5; i++) {
console.log(`Sample ${i + 1}:`, generateRandomData());
}
// Random quotes array
const randomQuotes = [
"The only way to do great work is to love what you do. - Steve Jobs",
"Innovation distinguishes between a leader and a follower. - Steve Jobs",
"Life is what happens to you while you're busy making other plans. - John Lennon",
"The future belongs to those who believe in the beauty of their dreams. - Eleanor Roosevelt",
"It is during our darkest moments that we must focus to see the light. - Aristotle"
];
console.log('Random Quote:', randomQuotes[Math.floor(Math.random() * randomQuotes.length)]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment