Random Big Number
Closed this issue · 2 comments
twodayslate commented
It would be great if you could get a random big number.
Below are my proposed function stubs
//: Generate a BInt between 0 and `upperBound`
public func random(upperBound: BInt) -> BInt
//: Generate a BInt between low and high
public func random(low: BInt, high: BInt) -> BInt
//: Generate a BDouble between 0 and upperBound
public func random(upperBound: BDouble) -> BDouble
//: Generate a BDouble between low and high
public func random(low: BDouble, high: BDouble) -> BDouble
class BInt {
//: Generate a BInt between 0 and `upperBound`
class public func random(upperBound: BInt) -> BInt
//: Generate a BInt between low and high
class public func random(low: BInt, high: BInt) -> BInt
}
class BDouble {
//: Generate a random DBouble between 0 and 1
class public func random() -> BDouble
//: Generate a BDouble between 0 and upperBound
class public func random(upperBound: BDouble) -> BDouble
//: Generate a BDouble between low and high
class public func random(low: BDouble, high: BDouble) -> BDouble
}
Both global and class functions would be available.
Thoughts? Ideas on implementation?
mkrd commented
The class BIntMath already implements "static func randomBInt(bits n: Int) -> BInt". I don't know how to specify upper and lower bounds, but mostly, you don't need big numbers in a specific range, but of a specific size anyways.
In regards to BDouble, I can't think of any application where you would need a random BDouble? I would ignore that for now, and maybe implement it if we find a use case that requires it
twodayslate commented
Fair enough.
I'm using this library for a game so random numbers are somewhat useful.