---
title: "C 获得随机数"
author: "Fecoly"
date: "2012-08-19T14:59:03Z"
tags: []
categories: ["编程语言"]
slug: "c"
draft: false
lastmod: "2012-08-19T14:59:03Z"
id: 1637286
url: "https://fecoly.iteye.com/blog/1637286"
---

#include <iostream>

using namespace std;

time_t temp_time;
srand((unsigned)time(&temp_time));//初始化随机种子
int r = (rand() % 256); //0-255
int r1 = (rand() % 10); //0-9
int r2 = (rand() % 100); //0-99