Skip to content

CodiceFiscale generator is not deterministic #632

@Mephistofeles

Description

@Mephistofeles

Bogus NuGet Package

35.6.5

.NET Version

.NET 10

Visual Studio Version

No response

What operating system are you using?

Windows

What locale are you using with Bogus?

it

Problem Description

Given a static seed CodiceFiscale should generate a deterministic code, like other generators, but it doesn't. It depends on GetHashCode(), which itself is not deterministic.

LINQPad Example or Reproduction Steps

public sealed class Player
{
    public required Guid Id { get; set; }
    public required string FirstName { get; set; }
    public required string LastName { get; set; }
    public required string TaxCode { get; set; }
}

Randomizer.Seed = new Random(9612867);

var testPlayers = new Faker<Player>("it")
    .StrictMode(true)
    .RuleFor(x => x.Id, f => f.Random.Guid())
    .RuleFor(x => x.FirstName, f => f.Name.FirstName())
    .RuleFor(x => x.LastName, f => f.Name.LastName())
    .RuleFor(x => x.TaxCode, f => f.Person.CodiceFiscale());

var players = testPlayers.Generate(2);

Expected Behavior

Every time I run the test using this code it should produce the exact same codes.

Actual Behavior

Every run Bogus generates a different codes.

Known Workarounds

No response

Could you help with a pull-request?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions