Skip to content

Commit

Permalink
Swift 4.2: Rename Random to SystemRandomNumberGenerator (#6)
Browse files Browse the repository at this point in the history
* Rename Random to SystemRandomNumberGenerator for Swift 4.2

* Update Swift version

* Set swift version to development snapshot

* Set swift version to development snapshot

* Set swift version to development snapshot

* Remove Swift 4.2 check since the Random change was apparently backported

* Optimistically update to latest Swift 4.2 snapshot

* try Swift version 4.2

* will this kind of version string work?

* ok fine convergence it is

* try compiling without the +Random extension

* temporarily remove RandomAccessCollection conformance

* update +Random.swift to 4.2 APIs

* build on macOS instead
  • Loading branch information
greg authored and stephencelis committed Aug 31, 2018
1 parent 6cb3612 commit 2a835f5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1
swift-4.2-CONVERGENCE
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
os:
- linux
- osx
osx_image: xcode10
env:
language: generic
sudo: required
dist: trusty
install:
- if [ $TRAVIS_OS_NAME = linux ]; then
eval "$(curl -sL https://swiftenv.fuller.li/install.sh)";
Expand Down
18 changes: 13 additions & 5 deletions NonEmpty.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
80CD742220D58E11004E5F60 /* NonEmpty+Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NonEmpty+Array.swift"; sourceTree = "<group>"; };
80EFFA6020D5A1BE00B265AE /* NonEmpty+Random.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NonEmpty+Random.swift"; sourceTree = "<group>"; };
"NonEmpty::NonEmpty::Product" /* NonEmpty.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = NonEmpty.framework; sourceTree = BUILT_PRODUCTS_DIR; };
"NonEmpty::NonEmptyTests::Product" /* NonEmptyTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = NonEmptyTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
"NonEmpty::NonEmptyTests::Product" /* NonEmptyTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = NonEmptyTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
OBJ_14 /* NonEmptyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonEmptyTests.swift; sourceTree = "<group>"; };
OBJ_16 /* NonEmpty.xcworkspace */ = {isa = PBXFileReference; lastKnownFileType = wrapper.workspace; path = NonEmpty.xcworkspace; sourceTree = SOURCE_ROOT; };
OBJ_6 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -235,6 +235,14 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 9999;
TargetAttributes = {
"NonEmpty::NonEmpty" = {
LastSwiftMigration = 1000;
};
"NonEmpty::NonEmptyTests" = {
LastSwiftMigration = 1000;
};
};
};
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "NonEmpty" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -331,7 +339,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGET_NAME = NonEmpty;
};
name = Debug;
Expand All @@ -356,7 +364,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGET_NAME = NonEmpty;
};
name = Release;
Expand Down Expand Up @@ -453,7 +461,7 @@
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGET_NAME = NonEmptyTests;
};
name = Debug;
Expand All @@ -474,7 +482,7 @@
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGET_NAME = NonEmptyTests;
};
name = Release;
Expand Down
11 changes: 7 additions & 4 deletions Sources/NonEmpty/NonEmpty+Random.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#if swift(>=4.1.5)
#if swift(>=4.2)
extension NonEmpty {
public func randomElement<T: RandomNumberGenerator>(using generator: inout T) -> Element {
return ContiguousArray(self).randomElement(using: &generator) ?? self.head
}

public func randomElement() -> Element {
return self.randomElement(using: &Random.default)
var generator = SystemRandomNumberGenerator()
return self.randomElement(using: &generator)
}
}

Expand All @@ -17,7 +18,8 @@ extension NonEmpty where C: RangeReplaceableCollection {
}

public mutating func shuffle() {
self.shuffle(using: &Random.default)
var generator = SystemRandomNumberGenerator()
self.shuffle(using: &generator)
}

public func shuffled<T: RandomNumberGenerator>(using generator: inout T) -> NonEmpty {
Expand All @@ -27,7 +29,8 @@ extension NonEmpty where C: RangeReplaceableCollection {
}

public func shuffled() -> NonEmpty {
return self.shuffled(using: &Random.default)
var generator = SystemRandomNumberGenerator()
return self.shuffled(using: &generator)
}
}
#endif

0 comments on commit 2a835f5

Please sign in to comment.