%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/pythran/pythonic/numpy/random/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/pythran/pythonic/numpy/random/bytes.hpp

#ifndef PYTHONIC_NUMPY_RANDOM_BYTES_HPP
#define PYTHONIC_NUMPY_RANDOM_BYTES_HPP

#include "pythonic/include/numpy/random/bytes.hpp"
#include "pythonic/include/numpy/random/generator.hpp"

#include "pythonic/types/str.hpp"
#include "pythonic/utils/functor.hpp"

#include <random>
#include <string>

PYTHONIC_NS_BEGIN
namespace numpy
{
  namespace random
  {

    types::str bytes(long length)
    {
      // dummy init + rewrite is faster than reserve && push_back
      types::str result(std::string(length, 0));
      std::uniform_int_distribution<long> distribution{0, 255};
      std::generate(result.chars().begin(), result.chars().end(), [&]() {
        return static_cast<char>(distribution(details::generator));
      });
      return result;
    }
  }
}
PYTHONIC_NS_END

#endif

Zerion Mini Shell 1.0