GithubHelp home page GithubHelp logo

ceylon-random's People

Contributors

jvasileff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

renatoathaydes

ceylon-random's Issues

Improve testing of all bits

Tests currently fail to detect the deficiency in node's RNG that results in only 32 bits of entropy.

shared native("js")
Random platformRandom() => object
        satisfies Random {

    value two53 = 2^53;

    shared actual
    Float nextFloat() {
        dynamic {
            return Math.random();
        }        
    }

    shared actual
    Integer nextBits(Integer bits) {
        if (bits <= 0) {
            return 0;
        }
        else if (bits <= 53) {
            return (nextFloat() * two53).integer / 2^(53-bits);
        }
        else {
            throw Exception(
                "bits cannot be greater than \
                 ``randomLimits.maxBits`` on this platform");
        }
    }
};

shared void run() {
    value random = platformRandom();
    printAll( { random.nextFloat() * (2.0^53) }.cycled.map((i)
            =>  formatInteger(i.integer, 2)).take(10), "\n");
}

Produces the output below, but the RNG still passes all tests.

$ ceylon run-js com.vasileff.ceylon.random.api
11011000111101100101101010010100000000000000000000000
10000101010011000111000010100010000000000000000000000
11010010010010101000010110001010000000000000000000000
1011001001101001010010100100011000000000000000000000
1110011010101101011011010101111000000000000000000000
10100110011101011011101011101110000000000000000000000
10100101011111011111001010101011000000000000000000000
10001101110001100010000110010101000000000000000000000
11010000001010100001111100000001000000000000000000000
10101101011100010101101001011011000000000000000000000

add methods/properties to Random that return streams

A very common use case is to generate more than one random value at a time - a sequence, stream, iteration, whatever. The current API forces you to do something like { random.nextBoolean() }.cycled or (0:10).map((_) random.nextBoolean()). It might be nice to provide convenience methods/properties to support random.booleans.take(10).

I've added bits(Integer bits), integers(Integer bound), booleans, bytes, floats, and elements(elements), all returning streams. At least for now, they are annotated deprecated("experimental").

Remove dependency on com.vasileff.ceylon.xmath

Hi!

I like your random library and want to contribute some code to it...

But before I get to that, I hope you don't mind if I give some suggestions. For example, I think it's not a good idea to mix this library with your xmath library. The Random library has the potential to become the de-facto random library in Ceylon, but if you start demanding people who only need a silly random generator to get a few things a little less deterministic to download more than one library (and this case it would be a shared import) this may make it more troublesome than it should be.

My suggestion would be to create some random generators in the xmath library itself, or even make it fully modular and have a xmath.random module with random functions that work with xmath and integrates with random.

Getting too low level of randomness with LCGRandom

I have some tests that require the generation of random Strings. I wrote it based on Random.elements( characters ).take(n);.

My test fails quite frequently now... I was using my own poor implementation of random before and it actually never failed.

If the randomness is good, I would expect duplicate Strings only every several billion Strings, but I am using only 100 Strings.

Could you confirm that this Random implementation has some kind of bias (maybe the default seed is very bad or something?).

Here's the implementation of randomStrings():

https://github.com/renatoathaydes/specks/blob/master/source/com/athaydes/specks/generators.ceylon#L60

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.