Skip to content

Unneeded double initialization in Random class>>seed: #17510

Closed
@tinchodias

Description

@tinchodias

Instances of Random have a seed. The seed can be explicitly set on creation (via seed:), or it can be generated from current timestamp (via new). I wanted to see how much slower is to generate the seed, so wrote this benchmark:

{
[ Random new ].
[ Random seed: 7 ].
} collect: #bench.

But discovered that new was faster than seed:, and it doesn't make sense:

  • new: 549,165 per second
  • seed: 295,684 per second

What happens is that Random seed: 7 first initializes the instance with a timestamp-based seed, and immediately after overrides it with the explicitly set.

This is in Pharo 12 and 13. I have a PR to fix it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions