rand()函数每次C都会产生相同的输出

时间:2019-02-23 23:59:53

标签: c visual-studio random

我正在尝试使用; The use of the Data contained in Verisign Inc.'s aggregated ; .com, and .net top-level domain zone files (including the checksum ; files) is subject to the restrictions described in the access Agreement ; with Verisign Inc. $ORIGIN COM. $TTL 900 @ IN SOA a.gtld-servers.net. nstld.verisign-grs.com. ( 1539446539 ;serial 1800 ;refresh every 30 min 900 ;retry every 15 min 604800 ;expire after a week 86400 ;minimum of a day ) $TTL 172800 NS A.GTLD-SERVERS.NET. NS G.GTLD-SERVERS.NET. NS H.GTLD-SERVERS.NET. NS C.GTLD-SERVERS.NET. NS I.GTLD-SERVERS.NET. NS B.GTLD-SERVERS.NET. NS D.GTLD-SERVERS.NET. NS L.GTLD-SERVERS.NET. NS F.GTLD-SERVERS.NET. NS J.GTLD-SERVERS.NET. NS K.GTLD-SERVERS.NET. NS E.GTLD-SERVERS.NET. NS M.GTLD-SERVERS.NET. COM. 86400 DNSKEY 257 3 8 AQPDzldNmMvZFX4NcNJ0uEnKDg7tmv/F3MyQR0lpBmVcNcsIszxNFxsBfKNW9JYCYqpik8366LE7VbIcNRzfp2h9OO8HRl+H+E08zauK8k7evWEmu/6od+2boggPoiEfGNyvNPaSI7FOIroDsnw/taggzHRX1Z7SOiOiPWPNIwSUyWOZ79VmcQ1GLkC6NlYvG3HwYmynQv6oFwGv/KELSw7ZSdrbTQ0HXvZbqMUI7BaMskmvgm1G7oKZ1YiF7O9ioVNc0+7ASbqmZN7Z98EGU/Qh2K/BgUe8Hs0XVcdPKrtyYnoQHd2ynKPcMMlTEih2/2HDHjRPJ2aywIpKNnv4oPo/ COM. 86400 DNSKEY 256 3 8 AQPepKpvbFtHVsAVm8kq+659WxFYXre5ngCIL53NuAMPybKPNEqgzF4+7GJExZB9LIDTH3ZK4QYAm7R14wEf9qGAjOpyIGF2jXqMkQ2G272hbEkFw6q5fawQByh3K7rXY8SAf2abpiXXh+Ms6LsvMarOpc7SwEt7Dbp1nvqgCA9jHw== COM. 86400 DNSKEY 256 3 8 AQPeabgR6Fgrk5FSLilDYUedwsHA0HH22e8+Zp/uvp4aj1dVDAy5C9bkRA+xot3sG1KaT5hvgoE7eNV93F7pBW9rvVE3A/BNvJbLXxKhkAJV5KMFC10NRcdb+xF+sM4XTMPESPrYwTLUEpSFntMIVLAtUzLaBo6YpTVR20osgGgc3Q== COM. 86400 NSEC3PARAM 1 0 0 - COM. 86400 RRSIG NSEC3PARAM 8 1 86400 20181019044209 20181012033209 46475 COM. l0FoGsy2lG+9tlm2AA2wPNDAJV2PwhTVjUbSqGMcJqWc8ZTXlnUkaWnje4ws7KmAJIyQe3dMQ/RnZoF0CQluNilPWWVNm/Zz01r+M96V288H36UiiP0aPX9OcPaSCxRumuZmeiHNOWmMm+fbwNtPSJa3IkxKXMM1dT0qJ24n5v8= COM. RRSIG NS 8 1 172800 20181019044209 20181012033209 46475 COM. LPV6Rjixhji/PQonHzKlnPxen/R/mZugUaj+fSpSQzQ7o4YLzZZ0k0J8linUu+RvdeI3p7+mdnUp5OergS7LAIsE2cQcvTpggJsi8aZk6r7QeqlvcYIEZfQ9vNpUVmZ/649SXvQppSq/RBbM4e0a1QQlUzXKiEUU53VDq2CUcnk= COM. 900 RRSIG SOA 8 1 900 20181020160219 20181013145219 46475 COM. dbMGDD6f+2EEZMigc6FbzUj8Ou05s5iUmg7fhrKRu4vRUhZoG1MNqJ8Jy1LtyUTRswtp2xhY+n7g7zBxNBlpgOnseovEjmuEUz34P6h40jkSKvk75iSVKc9tFLciZi0svVQFL7B3eVKRR/zGsY6z4qX9cPWJHh5wwLYO3JgsQls= COM. 86400 RRSIG DNSKEY 8 1 86400 20181019182533 20181004182033 30909 COM. vnSL1FfsX1/3qQw8ee20JqOAa9UNEvNjgCEmMu6HHfgQTKFy15DLMOA5VIWja6fbtASkc8YHJ5PWowWpWGiX9gE0g5i3TlMpiu6H3MQBjMgJWhtivzruEo4k2OknKRpfV18+rVf0MB55OAbqGS/J838PUFiYs7Rt7W7gYdFNRhWzS6VbdHElub0ySy4ZJTAt0muG7MphffC/Fgh9drgL0mpjfD2HynBbCKtgXOXJ6fHT6erkN2hMxu0AkJVwReNsQagOddtsK7RPPo1hfe5oZYBigVWtE/rvj6zHrRNKbyIcz+4fXpGmgayB2TACWc8vvRqcB3+VDaGxzIV4hGBo7Q== KITCHENEROKTOBERFEST NS NS1.UNIREGISTRYMARKET.LINK. KITCHENEROKTOBERFEST NS NS2.UNIREGISTRYMARKET.LINK. KITCHENFLOORTILE NS NS1.UNIREGISTRYMARKET.LINK. KITCHENFLOORTILE NS NS2.UNIREGISTRYMARKET.LINK. KITCHENTABLESET NS NS1.UNIREGISTRYMARKET.LINK. KITCHENTABLESET NS NS2.UNIREGISTRYMARKET.LINK. KITEPICTURES NS NS1.UNIREGISTRYMARKET.LINK. KITEPICTURES NS NS2.UNIREGISTRYMARKET.LINK. 函数生成从0到3的随机数,并且它工作得很好,但是我注意到有些奇怪。

每次我运行并重新运行项目时,该功能都会不断产生相同的数字模式。

这是我使用的尽可能简单的代码。

rand()

这会打印从0到3的15个随机数,对我来说这就是我得到的

#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int randomNumber; for (int i = 0; i < 15; i++) { randomNumber = rand() % 4; printf("%d ", randomNumber); } getchar(); return 0; }

这很好。但是问题是,每次我运行该程序时,都会打印出完全相同的内容。

知道为什么会这样吗?

1 个答案:

答案 0 :(得分:1)

在计算机科学中,没有像随机数这样的东西。因此,要生成不同的输出,我们必须使用伪随机。为此,请将srand(time(0))写入声明变量的位置。