This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |