檔案讀取 獲取隨機數 轉換中文時間的方法

2021-07-27 16:55:22 字數 2328 閱讀 7816

/**

* 讀取檔案最後n行

* * 根據換行符判斷當前的行數, 使用統計來判斷當前讀取第n行

* * ps:輸出的list是倒敘,需要對list反轉輸出

* * @param file

* 待檔案

* @param numread

* 讀取的行數

* @return list*/

public static string readlastnline(file file, long numread)

// 使用隨機讀取

randomaccessfile fileread = null;

try else }}

if (pos == 0)

}} catch (ioexception e) finally catch (exception e)

}} return rel;

}

**

* 順序

*@author lh

*@data 2023年8月16日

* @param file

* @param offset

* @param numread

* @return

*/public static string readlineasc(file file, int offset,int numread)

randomaccessfile fileread = null;

try else

if(count > end)}}

for(int k =0;k

/*** 倒序

*@author lh

*@data 2023年8月16日

* @param file

* @param offset

* @param numread

* @return

*/public static string readlinedesc(file file, int offset,int numread)

randomaccessfile fileread = null;

try else

if(count > end)}}

for(int k = lines.length -1;k >=0;k--)

}} catch (ioexception e) finally catch (exception e)

} }return sb.tostring();

}

public static string timetran(string times)else if(time > (1000 * 60 * 60))else if(time > (1000 * 60))

return time/1000 + "秒";

}

/**

* 獲取指定範圍內的隨機數

*@author lh

*@data 2023年11月11日

* @param min

* @param max

* @param number

* @return

*/public static int getrandom(int min, int max)

/**

* 獲取指定範圍內的隨機數 並且不等於指定的數字

*@author lh

*@data 2023年11月11日

* @param min

* @param max

* @param number

* @return

*/public static int getrandom(int min, int max,int number)

else

}

/**

* 獲取指定範圍內的隨機數 並且不等於指定的數字集合

*@author lh

*@data 2023年11月11日

* @param min

* @param max

* @param number

* @return

*/public static string getrandom(int min, int max,listnumberlist)

else

}else

}

獲取隨機數

c 中提供了隨機數函式rand 但是這個函式其實提供的數字是有限的,大概是0 32767,所以這就導致了兩個問題 1 獲取的的數字並不是隨機的,比如要取0 99的隨機數,那麼一般就是rand 100,由於32767 100 67,所以0 67的數字獲得到的次數會比68 99多一次。2 無法獲取到比3...

Ext 獲取隨機數與系統時間

extjs取系統時間就和js一樣 var mydate new date 得到系統日期 mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 mydate.getmonth 獲取當前月份 0 11,0代表1月 mydate.getda...

php 獲取隨機數

獲得最小和最大值之間隨機數,位數不足補零 function getrandnumber fmin fmax fileid date ymd his rand 100,999 fileid為 20100903 132121 908 這樣的的隨機數 function randomkeys length ...