Skip to content

Instantly share code, notes, and snippets.

@reinder42
Created May 11, 2019 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinder42/3d16e7f0249d4f87255f0402ea2f4fc4 to your computer and use it in GitHub Desktop.
Save reinder42/3d16e7f0249d4f87255f0402ea2f4fc4 to your computer and use it in GitHub Desktop.
Generate a string of random words
// Generates a random string of words
// Words courtesy of hipsum.co
import Foundation
func hipsum(_ count:Int = 8) -> String
{
// Split words and shuffle
var words = "Lorem ipsum dolor amet pinterest waistcoat live-edge kogi salvia umami tumblr YOLO organic vice fixie twee vinyl wolf gentrify hammock green juice pitchfork neutra YOLO cred art party pitchfork vegan tousled organic tilde drinking vinegar master cleanse chambray forage literally offal listicle food truck beard four dollar toast ethical pug DIY reindeer VHS salvia squid franzen echo park literally ugh godard thundercats next level pop-up keytar kogi truffaut hell of street art occupy prism tbh gentrify asymmetrical forage mustache plaid kitsch unicorn sriracha poutine photo booth roof party".split(separator: " ").shuffled()
// Slice array, map to strings, concatenate
let result = words[..<min(count, words.count)].map({ String($0) }).joined(separator: " ")
// Capitalize first letter and return
return result.prefix(1).capitalized + result.dropFirst() + "."
}
// Gimme!
print(hipsum(10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment