Skip to content

Pseudorandom number generator #135

Closed
@masuday

Description

@masuday

EDIT: An updated proposal is available below.

There are a few suggestions to have pseudorandom number generators (PRNGs) in the library, e.g., #1 (comment) and #104 (comment). Focusing on the uniform floating-point PRNG [0.0, 1.0), we have already had the intrinsic subroutine, random_number. The first question is whether we should have custom PRNGs of the uniform distribution. Or, we should concentrate on derived PRNGs like non-uniform distributions or integer PRNGs. I think it is still worth developing custom PRNGs because of better flexibility and performance.

With the custom PRNGs, we have many more questions.

  • Should we have various generators (e.g., integer numbers) in addition to a floating-point PRNG [0.0, 1.0)?
  • Should it support different algorithms of PRNG, or can we provide a single algorithm?
    • If true: Should it optionally call the intrinsic subroutine?
    • If true: Should the seed (state) be global, private, or both?
      • If global, Should it be thread-safe?

The decision defines a design of API. A possible API is the same as the intrinsic subroutines. The subroutine name in the below example is just a placeholder.

! just arbitrary precision here
type(random_number_generator) :: rng
real(dp) :: harvest
integer :: seed(2)

! for local state as derived type
seed = [1,2]
call pseudorandom_seed(rng,put=seed)
call pseudorandom_number(rng,harvest)

! for global state as saved seed
call pseudorandom_seed(put=seed)
call pseudorandom_number(harvest)

Please tell me what you think about it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: algorithmssearching and sorting, merging, ...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions