Skip to content

Instantly share code, notes, and snippets.

Avatar
🎧
Writing code

Tom Busby tombusby

🎧
Writing code
View GitHub Profile
@tombusby
tombusby / personnummer.rb
Created Sep 12, 2019 — forked from henrik/personnummer.rb
Generate valid Swedish personnummer.
View personnummer.rb
# 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