openssl rand 產生隨機數

2021-06-09 14:12:53 字數 717 閱讀 9424

介紹openssl rand 用於產生指定長度個bytes的隨機字元。

語法openssl rand[-outfile] [-randfile(s)] [-base64] [-hex]num

e:\openssl\foo>openssl rand 10

騆oading 'screen' into random state - done

t嬍鴢va

可以看見,這10個位元組的隨機數顯示為亂碼,可以用 -out 將隨機字元放到乙個檔案中

-base64 / -hex對隨機字串進行base64編碼或用hex格式顯示

e:\openssl\foo>openssl rand -hex 10

loading 'screen' into random state - done

325567f39cb3dbf15a32

e:\openssl\foo>openssl rand -base64 20

loading 'screen' into random state - done

aa58hkadrquix1jfr4cocm9m/ne=

隨機產生漢字

region 產生n個隨機的漢字 產生n個隨機的漢字 產生的隨機漢字個數 public static string getrandomchinese intstrlength 此函式在漢字編碼範圍內隨機建立含兩個元素的十六進製制位元組陣列,每個位元組陣列代表乙個漢字,並將 四個位元組陣列儲存在obj...

產生隨機數

先說明一下rand,這個函式用來產生偽隨機數。比如,產生1000的兩個隨機數,產生的兩個一般上是不同的,但如果要產生80個100以內的隨機數,僅用rand函式就不夠。因為產生80個100以內的隨機數,至少有兩個數相等的概率太大了 srand函式,並不能使產生的隨機數完全不同。你可以執行以下這串 in...

隨機序列產生演算法

題目 已經提供乙個int rand int n 的隨機數生成函式用來生成 0,n 的隨機數,求編寫演算法生成1至n的隨機序列,要求該序列包含不重複的1 n數字。include include include using namespace std 首先,建立乙個長度為n的陣列array,初始值是0 ...