- Proposal: SE-NNNN
- Author: Alejandro Alonso
- Review Manager: TBD
- Status: Awaiting review
- Implementation: apple/swift#19743
- Proposal: SE-NNNN
- Author: Alejandro Alonso
- Review Manager: TBD
- Status: Awaiting implementation
This proposal aims to add a new method, fillBuffer(_:)
, to RandomNumberGenerator
, and aims to move an already defaulted method into a requirement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
int solve_capcha(int *ptr, int size) { | |
int tmp = 0; | |
for (int i = 0; i < size; i++) { | |
int index = i - 1; | |
if (i == 0) { | |
index = size - 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Date : Randomizable, Strideable { | |
typealias Stride = Int | |
let timestamp: UInt32 | |
static func random<T: RandomNumberGenerator>(using generator: T) -> Date { | |
return Date(timestamp: (0 ... UInt32.max).random!) | |
} | |
func distance(to other: Date) -> Int { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Darwin | |
public protocol RandomGenerator { | |
func next<T : FixedWidthInteger>(_ type: T.Type) -> T | |
func next<T : FixedWidthInteger>(_ type: T.Type, upperBound: T) -> T | |
} | |
public enum Random : RandomGenerator { | |
case `default` | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol RandomSource { | |
static var shared: RandomSource { get } | |
func next<T : FixedWidthInteger>(_ type: T.Type) -> T | |
func nextUniform<T : BinaryFloatingPoint>(_ type: T.Type) -> T | |
} | |
// Utilizes /dev/urandom | |
public class DevRandom: RandomSource { | |
public static let shared = DevRandom() | |
NewerOlder