On 8/2/11 6:42 AM, Jesse Phillips wrote:
auto arr = new int[1024];
fill(arr, randomCover(iota(0,1024), rndGen));
Note that this produces a random permutation of the numbers 0 to 1023,
which may or may not be what you want.
David
Andrej Mitrovic:
> Maybe..
>
> auto max = 1024;
> auto len = 1024;
>
> arr = rndRange(max)[0..len];
In my opinion that's not general enough for Phobos, see the N dimensional
table() I have explained here:
auto arr = table!q{ uniform(0, 1024) }(1024);
http://www.digitalmars.com/webnews/newsgro
Woops you're right about the range type being returned.
I guess this is the next best thing:
arr = array(rndRange(max, len));
On 02.08.2011 16:08, Andrej Mitrovic wrote:
On 8/2/11, Pelle wrote:
Without UFCS, well, how would you want it to look?
Maybe..
auto max = 1024;
auto len = 1024;
arr = rndRange(max)[0..len];
IOW, using the slice operator instead of a call to array().
It could be done , but IMO a lot of gener
On 8/2/11, Pelle wrote:
> Without UFCS, well, how would you want it to look?
Maybe..
auto max = 1024;
auto len = 1024;
arr = rndRange(max)[0..len];
IOW, using the slice operator instead of a call to array().
On Mon, 01 Aug 2011 21:43:13 +0200, Andrej Mitrovic
wrote:
Actually I don't really need *uniform* distribution, it's just that
when porting C code to D I didn't find any obvious random()/rnd()
functions, and uniform seemed to be the closest thing without having
to mess around with a bunch of
On Tue, 02 Aug 2011 03:48:03 +0200, David Nadlinger wrote:
> On 8/2/11 3:40 AM, Jesse Phillips wrote:
>> Andrej Mitrovic Wrote:
>>> Is there a simpler way to do get an array of random values?
>>
>> Untested:
>>
>> auto arr = new int[1024];
>> fill(arr, uniform(0, 1024));
>
> This does a great job
On 8/2/11 3:40 AM, Jesse Phillips wrote:
Andrej Mitrovic Wrote:
Is there a simpler way to do get an array of random values?
Untested:
auto arr = new int[1024];
fill(arr, uniform(0, 1024));
This does a great job of creating an array containing the same random
value 1024 times. ;)
David
Andrej Mitrovic Wrote:
> I'm currently using this:
>
> import std.algorithm;
> import std.array;
> import std.random;
> import std.range;
>
> void main()
> {
> auto arr2 = array(map!( (int){ return uniform(0, 1024); })(iota(0,
> 1024)));
> }
>
> Is there a simpler way to do get an array of
> On 01.08.2011 23:43, Andrej Mitrovic wrote:
> > Actually I don't really need *uniform* distribution, it's just that
> > when porting C code to D I didn't find any obvious random()/rnd()
> > functions, and uniform seemed to be the closest thing without having
> > to mess around with a bunch of ran
On 01.08.2011 23:43, Andrej Mitrovic wrote:
Actually I don't really need *uniform* distribution, it's just that
when porting C code to D I didn't find any obvious random()/rnd()
functions, and uniform seemed to be the closest thing without having
to mess around with a bunch of randomization param
On 8/1/11, Adam D. Ruppe wrote:
> I'm barely following this thread, but why not:
>
> ===
> import std.random;
> void main() {
> int[] arr;
> foreach(i; 1 .. 100)
> arr ~= uniform(0, 1024);
> }
> ===
>
> ?
>
Ah but nearly every initialization can be converted to a foreach loop.
Bu
David Nadlinger:
> I'd argue it does with 1024⦠;)
Right, I am sorry :-)
Bye,
bearophile
I'm barely following this thread, but why not:
===
import std.random;
void main() {
int[] arr;
foreach(i; 1 .. 100)
arr ~= uniform(0, 1024);
}
===
?
Actually I don't really need *uniform* distribution, it's just that
when porting C code to D I didn't find any obvious random()/rnd()
functions, and uniform seemed to be the closest thing without having
to mess around with a bunch of randomization parameters which I don't
care about.
I don't see h
On 8/1/11 8:55 PM, bearophile wrote:
David Nadlinger:
array(map!"a % 1024"(take(rndGen(), 1024))).
% doesn't give an uniform distribution.
I'd argue it does with 1024… ;)
David
David Nadlinger:
> if you do need a limit, that would be
> array(map!"a % 1024"(take(rndGen(), 1024))).
% doesn't give an uniform distribution.
Bye,
bearophile
On 7/30/11 5:10 PM, Andrej Mitrovic wrote:
Is there a simpler way to do get an array of random values?
If you don't need the random numbers to be in a certain range, you could
use array(take(rndGen(), 1024)) – if you do need a limit, that would be
array(map!"a % 1024"(take(rndGen(), 1024))).
On 01.08.2011 18:05, Steven Schveighoffer wrote:
On Sat, 30 Jul 2011 11:10:38 -0400, Andrej Mitrovic
wrote:
I'm currently using this:
import std.algorithm;
import std.array;
import std.random;
import std.range;
void main()
{
auto arr2 = array(map!( (int){ return uniform(0, 1024);
})(io
On Sat, 30 Jul 2011 11:10:38 -0400, Andrej Mitrovic
wrote:
I'm currently using this:
import std.algorithm;
import std.array;
import std.random;
import std.range;
void main()
{
auto arr2 = array(map!( (int){ return uniform(0, 1024); })(iota(0,
1024)));
}
Is there a simpler way to do
Yeah I really like Python's list comprehensions. That's something I'll
always miss in D.
Andrej Mitrovic:
> void main()
> {
> auto arr2 = array(map!( (int){ return uniform(0, 1024); })(iota(0,
> 1024)));
> }
>
> Is there a simpler way to do get an array of random values?
If you want a single expression you are allowed to write a bit shorter code:
auto arr2 = array(map!((int){ r
I'm currently using this:
import std.algorithm;
import std.array;
import std.random;
import std.range;
void main()
{
auto arr2 = array(map!( (int){ return uniform(0, 1024); })(iota(0, 1024)));
}
Is there a simpler way to do get an array of random values?
23 matches
Mail list logo