---
name: "irandstream"
section: "3bobcat"
platform: "linux"
package: "libbobcat-dev"
version: "6.07.01-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/irandstream"
---

# irandstream(3bobcat)

Istream producing random numbers

## NAME

FBB::IRandStream - Istream producing random numbers

## SYNOPSIS

**#include \<bobcat/irandstream\>**\
 Linking option: *-lbobcat*

## DESCRIPTION

**FBB::IRandStream** objects may be used to extract random numbers in a given range from a stream.

## NAMESPACE

**FBB**\
 All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace **FBB**.

## INHERITS FROM

**std::istream**, \
 **FBB::RandBuffer** (private)

## CONSTRUCTORS

- o

  **IRandStream(int max)**:\
   This **FBB::IRandStream()** constructor initializes the random generator. The default seed (i.e., 1) for the [**srand**(3)](/srand/3.md) function is used, meaning that every new run of the program will generate the same sequence of random values. Another constructor (see below) is provided when this is not considered appropriate. Random values between 1 and *max* (inclusive) are returned.

-

  - o

  **IRandStream(int min, int max)**:\
   This **FBB::IRandStream()** constructor initializes the random generator. The default seed (i.e., 1) for the [**srand**(3)](/srand/3.md) function is used, meaning that every new run of the program will generate the same sequence of random values. Another constructor (see below) is provided when this is not considered appropriate. Random values between *min* and *max* (inclusive) are returned.

-

  - o

  **IRandStream(int min, int max, size\_t seed)**:\
   This **FBB::IRandStream()** constructor initializes the random generator. The seed is used to initialize the random number generator. To start the random generator at some unpredictable point, *time(0)* could be used. Random values between *min* and *max* (inclusive) are returned.

Copy and move constructors (and assignment operators) are not available.

## INHERITED MEMBERS

Since the class uses public derivation from **std::istream**, all members of this class can be used.

## EXAMPLE

```
#include <iostream>
#include <bobcat/irandstream>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
{
    if (argc == 1)
        cout << "\n"
                "Showing one random value between 1 and 1000 (inclusive).\n"
                "If you want more values specify the requested number of\n"
                "values as the program’s first argument\n"
                "On repeated calls the same numbers are generated\n\n";
    IRandStream in(1000);
    for (size_t count = argc == 1? 1 : stoul(argv[1]); count--; )
    {
        size_t random;
        in >> random;
        cout << random << endl;
    }
}
```

## FILES

*bobcat/irandstream* - defines the class interface

## SEE ALSO

[**bobcat**(7)](/bobcat/7.md), [**randbuf**(3bobcat)](/randbuf/3bobcat.md), [**randommt**(3bobcat)](/randommt/3bobcat.md)

## BUGS

None Reported.

## BOBCAT PROJECT FILES

- o

  *https://fbb-git.gitlab.io/bobcat/*: gitlab project page;

Debian Bobcat project files:

- o

  *libbobcat6*: debian package containing the shared library, changelog and copyright note;

- o

  *libbobcat-dev*: debian package containing the static library, headers, manual pages, and developer info;

## BOBCAT

Bobcat is an acronym of \`Brokken’s Own Base Classes And Templates’.

## COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

## AUTHOR

Frank B. Brokken (**f.b.brokken@rug.nl**).
