Skip to content

Instantly share code, notes, and snippets.

@peace2048
Created January 29, 2016 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peace2048/ccb5735e4e99d307912a to your computer and use it in GitHub Desktop.
Save peace2048/ccb5735e4e99d307912a to your computer and use it in GitHub Desktop.
Random

サンプルデータの作成

<Extension>
Public Iterator Function Repeat(Of T)(element As T) As IEnumerable(Of T)
	While True
		Yield element
	End While
End Function

<Extension>
Public Iterator Function Repeat(Of T)(source As IEnumerable(Of T)) As IEnumerable(Of T)
	While True
		For Each item In source
			Yield item
		Next
	End While
End Function

<Extension>
Public Iterator Function RandomUsing(Of T)(source As IEnumerable(Of T), random As Random) As IEnumerable<T>
	Dim list = source.ToList()
	While True
		Dim index = random.Next(list.Count)
		Yield list(index)
	End While
End Function

<Extension>
Public Function RandomOrderUsing(Of T)(source As IEnumerable(Of T), random As Random) As IEnumerable(Of T)
	Return source.OrderBy(Function(a) random.Next())
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment