| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1074 人关注过本帖
标题:随机数问题
只看楼主 加入收藏
菜鸟小袁
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-8-5
结帖率:100%
收藏
已结贴  问题点数:0 回复次数:2 
随机数问题
运行结果都是一样的随机数。 请问怎么改下 使得数组存储的是不同随机数啊,菜鸟在线等高手指点
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim arrData(9, 9) As Double

        Dim rand As New Random
        
        For i As Integer = 0 To 9
            For j As Integer = 0 To 9

                arrData(i, j) = rand.NextDouble()


            Next
        Next


        For Each strnNum As String In arrData

            For intI = 0 To 9

                For intJ = 0 To 9
                    Console.Write("arrdata[" + intI.ToString + " " + intJ.ToString + "] =" & strnNum)
                Next
                Console.WriteLine()
            Next
        Next

    End Sub
End Class
搜索更多相关主题的帖子: 随机数 
2009-08-12 09:27
sywzs
Rank: 10Rank: 10Rank: 10
来 自:辽宁
等 级:贵宾
威 望:15
帖 子:508
专家分:1725
注 册:2009-5-13
收藏
得分:5 
用 Randomize() 和 Rnd()  产生随机数
例如  Randomize()
      TextBox1.Text = Rnd() 或 TextBox1.Text = Rnd(Date.Now.Second)
2009-08-12 19:48
hd19861028
Rank: 1
等 级:新手上路
帖 子:6
专家分:7
注 册:2010-10-29
收藏
得分:0 
Dim arrData(9, 9) As Double

        Dim rand As New Random

        For i As Integer = 0 To 9
            For j As Integer = 0 To 9

                arrData(i, j) = rand.NextDouble()


            Next
        Next


        For intI As Integer = 0 To 9

            For intJ As Integer = 0 To 9
                Me.TextBox1.Text += arrData(intI, intJ).ToString()
            Next

        Next
2010-11-08 16:43
快速回复:随机数问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019719 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved