首页 > 代码库 > WPF产生不重复的随机数

WPF产生不重复的随机数

WPF产生不重复的随机数

在给定的区间范围(比如[50,99]),产生给定数量的随机数(不如10个),要求产生的随机数不重复
首先给定变量
min=50;
max=99+1;//习惯与程序规定的编码不同所致
n=10;
好了,上代码
1.xaml界面格式
<Grid>        <TextBlock x:Name="tb_Screen" HorizontalAlignment="Left" Margin="59,24,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top"/>        <Button x:Name="tb_Create" Content="Button" HorizontalAlignment="Left" Margin="144,259,0,0" VerticalAlignment="Top" Width="75" Click="tb_Create_Click"/>        <TextBox x:Name="txt_min" HorizontalAlignment="Left" Height="23" Margin="80,92,0,0" TextWrapping="Wrap" Text="50" VerticalAlignment="Top" Width="70" RenderTransformOrigin="0.462,2.179"/>        <TextBox x:Name="txt_max" HorizontalAlignment="Left" Height="23" Margin="257,92,0,0" TextWrapping="Wrap" Text="99" VerticalAlignment="Top" Width="82" RenderTransformOrigin="1.018,0.43"/>        <TextBlock HorizontalAlignment="Left" Margin="10,95,0,0" TextWrapping="Wrap" Text="min=" VerticalAlignment="Top"/>        <TextBlock HorizontalAlignment="Left" Margin="186,95,0,0" TextWrapping="Wrap" Text="max=" VerticalAlignment="Top"/>        <TextBox x:Name="txt_n" HorizontalAlignment="Left" Height="23" Margin="121,149,0,0" TextWrapping="Wrap" Text="10" VerticalAlignment="Top" Width="120"/>        <TextBlock HorizontalAlignment="Left" Margin="31,152,0,0" TextWrapping="Wrap" Text="数量" VerticalAlignment="Top"/></Grid>

详细说明:http://wp.662p.com/thread-8107-1-1.html