<div dir="ltr">I agree.<div><br></div><div>If there should be an API to produce a random Double without parameters then IMHO it should simply be a uniformly distributed Double in the unit range [0, 1). Very useful as a basic building block and can be constructed very fast from a random bitpattern like eg:</div><div><div>extension Double {</div><div> init(unitRange v: UInt64) {</div><div> self = Double(v >> Double.exponentBitCount) * (.ulpOfOne/2.0)</div><div> }</div><div>}</div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 10, 2018 at 11:48 PM, Saagar Jha <span dir="ltr"><<a href="mailto:saagar@saagarjha.com" target="_blank">saagar@saagarjha.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Which begs the question: why would you want to do something like this? Creating a “random” Double from its full range of values is an odd thing to do, and the fact that it is non-uniform and has irregularities like infinity and signed zeros makes it likely that any such usage is probably done in error (the one reason I can think of is if you’re trying to test your code with random Doubles, but I’d argue for keeping NaN in that case). Generally users are looking for uniform distributions or ones that follow some set pattern (e.g. normal, Bernoulli), so this doesn’t seem useful at all.<div><span class="HOEnZb"><font color="#888888"><br></font></span><div><span class="HOEnZb"><font color="#888888"><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">Saagar Jha</div>
</div></font></span><div><div class="h5">
<div><br><blockquote type="cite"><div>On Jan 10, 2018, at 14:39, Jens Persson <<a href="mailto:jens@bitcycle.com" target="_blank">jens@bitcycle.com</a>> wrote:</div><br class="m_-9151676914594798620Apple-interchange-newline"><div><div dir="ltr">On Wed, Jan 10, 2018 at 11:27 PM, Saagar Jha <span dir="ltr"><<a href="mailto:saagar@saagarjha.com" target="_blank">saagar@saagarjha.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Not a floating point expert, but are you sure this works? I have a feeling this would lead to a distribution that’s not uniform.<div><span class="m_-9151676914594798620gmail-HOEnZb"><font color="#888888"><br></font></span></div></div></blockquote><div><br></div><div>Yes, it would not be uniform, which is exactly what I meant by the last part of: "<span style="color:rgb(80,0,80);font-size:12.800000190734863px">Assuming you are ok with signed zero and infinities and "strange" bias as result of IEEE 754"</span></div><div><br></div><div>Also, I think it's impossible to get a uniform distribution of all non-Nan Double values (since they include +- infinity).</div><div><br></div><div><font color="#500050"><span style="font-size:12.800000190734863px">/Jens</span></font></div><div><font color="#500050"><span style="font-size:12.800000190734863px"><br></span></font></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div><span class="m_-9151676914594798620gmail-HOEnZb"><font color="#888888"><div>
<div style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">Saagar Jha</div>
</div>
</font></span><div><br><blockquote type="cite"><div><div class="m_-9151676914594798620gmail-h5"><div>On Jan 10, 2018, at 14:07, Jens Persson via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_-9151676914594798620gmail-m_3506493873590993612Apple-interchange-newline"></div></div><div><div><div class="m_-9151676914594798620gmail-h5"><div dir="ltr">On Tue, Jan 9, 2018 at 10:07 PM, Jonathan Hull via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div><div>One additional question. How do you ergonomically get a Double which doesn’t have a range, but also isn’t NaN?</div><div><div class="m_-9151676914594798620gmail-m_3506493873590993612gmail-h5"><div><br></div></div></div></div></div></blockquote><div><br></div><div>Assuming you are ok with signed zero and infinities and "strange" bias as result of IEEE 754:</div><div><div><br></div><div>func randomNonNanDouble<R: RandomNumberGenerator>(using generator: R) -> Double {</div><div> while true {</div><div> let rndUInt64 = generator.next()</div><div> let rndDouble = Double(bitPattern: rndUInt64)</div><div> if rndDouble != Double.nan { return rndDouble }</div><div> }</div><div>}<br></div></div><div><br></div><div>/Jens</div><div><br></div></div></div></div></div></div><span class="m_-9151676914594798620gmail-">
______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br></span></div></blockquote></div><br></div></div></blockquote></div><br></div></div>
</div></blockquote></div><br></div></div></div></div></div></blockquote></div><br></div>