Thread overview | ||||||
---|---|---|---|---|---|---|
|
August 07, 2015 Using std.random.uniform as a range | ||||
---|---|---|---|---|
| ||||
What is the best way to create range from uniform() function (in other words create a generator based on some function, returning, say, scalar, not range)? I did http://dpaste.dzfl.pl/53e3d9255cd7 but I'm not sure it's the best way. At least sequence using looks ugly |
August 07, 2015 Re: Using std.random.uniform as a range | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | On 08/07/2015 06:59 AM, drug wrote:
> What is the best way to create range from uniform() function (in other
> words create a generator based on some function, returning, say, scalar,
> not range)? I did http://dpaste.dzfl.pl/53e3d9255cd7 but I'm not sure
> it's the best way. At least sequence using looks ugly
There is an undocumented (why?) Generator struct and generate() functin in std.range:
import std.stdio;
import std.range;
import std.random;
void main()
{
auto r = generate!(() => uniform(0, 6))
.take(10);
writefln("%(%s %)", r);
}
Ali
|
August 08, 2015 Re: Using std.random.uniform as a range | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 08.08.2015 01:34, Ali Çehreli пишет:
> On 08/07/2015 06:59 AM, drug wrote:
>> What is the best way to create range from uniform() function (in other
>> words create a generator based on some function, returning, say, scalar,
>> not range)? I did http://dpaste.dzfl.pl/53e3d9255cd7 but I'm not sure
>> it's the best way. At least sequence using looks ugly
>
> There is an undocumented (why?) Generator struct and generate() functin
> in std.range:
>
> import std.stdio;
> import std.range;
> import std.random;
>
> void main()
> {
> auto r = generate!(() => uniform(0, 6))
> .take(10);
> writefln("%(%s %)", r);
> }
>
> Ali
>
Oh, thank you very much! That's what doctor prescribed.
|
August 08, 2015 Re: Using std.random.uniform as a range | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Friday, 7 August 2015 at 22:34:40 UTC, Ali Çehreli wrote: > There is an undocumented (why?) Generator struct and generate() functin in std.range: It's new in 2.068, that's why it's missing in the current docs. It's already in the prerelease docs: http://dlang.org/phobos-prerelease/std_range.html#.generate |
Copyright © 1999-2021 by the D Language Foundation