samedi 26 janvier 2019

I cant generate different random numbers inside for each looping [duplicate]

This question already has an answer here:

1- Copy and paste following codes into MainWindow.xaml

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="450" Width="450">
<StackPanel>
    <Button x:Name="Button1" Height="20" Width="100" VerticalAlignment="Top" Content="Generate Random"/>
    <DataGrid x:Name="DataGrid1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</StackPanel>
</Window>

2- Copy and paste following codes into code behind

Class MainWindow 

Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click

    Dim myDataTable As New System.Data.DataTable

    myDataTable.Columns.Add("Numbers")

    For k As Integer = 1 To 3

        Dim myRandom As New Random
        Dim myList As New List(Of Integer)(New Integer() {"10", "11", "12", "13", "14"})
        myList = myList.OrderBy(Function(i) myRandom.Next).ToList()

        For Each x As Integer In myList
            myDataTable.Rows.Add({x})
        Next

    Next

    DataGrid1.ItemsSource = myDataTable.DefaultView

End Sub

End Class

My question is here;

You will see this (https://prnt.sc/mcj14n) when you run this project and then click Generate Random Button.

I want to see this https://prnt.sc/mcj207

So, why I cant generate different random numbers inside for each looping?




Aucun commentaire:

Enregistrer un commentaire