Re: Confusion about `Random`

2022-12-23 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 23, 2022 at 03:21:24PM +, jwatson-CO-edu via Digitalmars-d-learn wrote: > On Friday, 23 December 2022 at 00:00:06 UTC, H. S. Teoh wrote: [...] > > My personal guess is that you forgot a `ref` somewhere when you pass > > the RNG to a function. Given that due to historical accident

Re: Preventing nested struct destructor accessing stack frame

2022-12-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/16/22 7:17 AM, Nick Treleaven wrote: This code segfaults when the GC calls the dtor after the unittest succeeds: ```d unittest {     int i;     struct S     {     ~this() { i++; }     }     (*new S).destroy; } ``` It seems destroy clears the context pointer. Is there a way to

Re: Confusion about `Random`

2022-12-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/23/22 10:07 AM, jwatson-CO-edu wrote: On Friday, 23 December 2022 at 00:58:01 UTC, Steven Schveighoffer wrote: Without the rest of the code, and how random is called, I have a hunch... Are you using threads by any chance? If, for instance, your calls to rand01 are done in a new thread,

Re: Confusion about `Random`

2022-12-23 Thread jwatson-CO-edu via Digitalmars-d-learn
On Friday, 23 December 2022 at 00:00:06 UTC, H. S. Teoh wrote: You could try using DustMite to reduce it to a minimal (or at least smaller) example. My personal guess is that you forgot a `ref` somewhere when you pass the RNG to a function. Given that due to historical accident std.random

Re: Confusion about `Random`

2022-12-23 Thread jwatson-CO-edu via Digitalmars-d-learn
On Friday, 23 December 2022 at 07:25:23 UTC, Salih Dincer wrote: You can try using static this. ```d import std.random; static this() { } // can try using Mt19937 rnd; void init_random() { rnd = Random(unpredictableSeed); } double rand01() { return uniform(0, 1.0, rnd); } void main()

Re: Confusion about `Random`

2022-12-23 Thread jwatson-CO-edu via Digitalmars-d-learn
On Friday, 23 December 2022 at 00:58:01 UTC, Steven Schveighoffer wrote: Without the rest of the code, and how random is called, I have a hunch... Are you using threads by any chance? If, for instance, your calls to rand01 are done in a new thread, that new thread will have a *default* state

Re: Preventing nested struct destructor accessing stack frame

2022-12-23 Thread Nick Treleaven via Digitalmars-d-learn
On Tuesday, 20 December 2022 at 06:31:09 UTC, ag0aep6g wrote: On 16.12.22 14:07, Nick Treleaven wrote: This seems to work:     ~this() @trusted { if ( > cast(void*)1024) i++; } It would be better if there was a struct property to get the context pointer though. A quick test suggests