Welcome to StackEdit! Hey! I’m your first Markdown document in StackEdit 1 . Don’t delete me, I’m very helpful! I can be recovered anyway in the Utils tab of the Settings dialog. Documents StackEdit stores your documents in your browser, which means all your documents are automatically saved locally and are accessible offline! Note: StackEdit is accessible offline after the application has been loaded for the first time. Your local documents are not shared between different browsers or computers. Clearing your browser’s data may delete all your local documents! Make sure your documents are synchronized with Google Drive or Dropbox (check out the Synchronization section). Create a document The document panel is accessible using the button in the navigation bar. You can create a new document by clicking New document in the document panel. Switch to another document All your local documents are listed in the document panel. You can switch from one to anoth...
Trong ANSI-C, để tạo ra các số giả ngẫu nhiên ta cần kết hợp 2 hàm số int rand(void) và void srand (unsigned int seed). Hai hàm số này nằm trong thư viện stdlib.h.
Ví dụ:
Ví dụ:
#include
#include
#include
int main(void)
{
int i;
srand(time(NULL));
i = rand();
printf ("Your random number is %d\n", i);
printf ("This compiler can generate random numbers from 0 to %d\n", RAND_MAX);
return(0);
}
Nếu không có hàm srand(unsigned int seed), hàm rand() luôn trả về một kết quả như nhau mỗi khi chạy chương trình, dù kết quả đó là "ngẫu nhiên".
Comments