Skip to content

Instantly share code, notes, and snippets.

View tombusby's full-sized avatar
🎧
Writing code

Tom Busby tombusby

🎧
Writing code
View GitHub Profile
@tombusby
tombusby / personnummer.rb
Created September 12, 2019 19:24 — forked from henrik/personnummer.rb
Generate valid Swedish personnummer.
# Generator for valid Swedish personnummer: http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
# By Henrik Nyh <http://henrik.nyh.se> 2009-01-29 under the MIT license.
require 'date'
module Personnummer
def self.generate(date=nil, serial=nil)
date ||= Date.new(1900+rand(100), 1+rand(12), 1+rand(28))
serial = serial ? serial.to_s : format("%03d", 1+rand(999)) # 001-999