導航:首頁 > 操作系統 > Android隨機數

Android隨機數

發布時間:2022-03-13 03:35:20

android 為什麼我創建的臨時文件名里有一串隨機數

File.createTempFile()
這個方法內部實現的時候 就是添加了隨機數。防止文件重復,創建失敗。

⑵ android 怎樣生成隨機數

java">Randomrnd=newRandom();
intrndint=rnd.nextInt(10000);

生成0~10000之間的隨機數

⑶ android隨機數

我有個辦法:

首先你應該有10張數字圖片,然後你在代碼中寫個String數組【0.。。9】數組中的項對應相應的數字圖片,比如1圖片對應String【1】,這樣圖片上的數字 你就可以拿到4個String字元串了 然後把4個字元串用StringBuider拼接起來轉化成一個String字元串 和editext.gettext拿到的數據作比較,相等返回true 否則返回false。

String[]s={"0","1","2","3","4","5","6","7","8","9"};
//比如圖片展示的1052
StringBuilderstringBuilder=newStringBuilder();
stringBuilder.append(s[1]).append(s[0]).append(s[5]).append(s[2]);
StringtoString=stringBuilder.toString();
e=editText.getText().toString();
if(toString.equals(e)){
returntrue;
}else{
returnfalse;
}

⑷ android點擊按鈕讓它出現隨機數

先把3個按鈕隱藏,點擊了按鈕A,就顯示3個按鈕
我試了下,可以的
test.xml:5767778<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=" android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/btA" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:text="按鈕A" /> <Button android:id="@+id/btB" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toLeftOf="@id/btA" android:text="按鈕B" /> <Button android:id="@+id/btD" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@id/btA" android:text="按鈕D" /> <Button android:id="@+id/btC" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/btA" android:layout_toLeftOf="@+id/btD" android:text="按鈕C" /></RelativeLayout> TestActivity:package com.example.androidtest;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;public class TestActivity extends Activity { private Button btA; private Button btB; private Button btC; private Button btD; private boolean isVisible = true; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); btA = (Button) findViewById(R.id.btA); btB = (Button) findViewById(R.id.btB); btC = (Button) findViewById(R.id.btC); btD = (Button) findViewById(R.id.btD); btB.setVisibility(View.INVISIBLE); btC.setVisibility(View.INVISIBLE); btD.setVisibility(View.INVISIBLE); btA.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (isVisible) { btB.setVisibility(View.VISIBLE); btC.setVisibility(View.VISIBLE); btD.setVisibility(View.VISIBLE); isVisible = false; } else { btB.setVisibility(View.INVISIBLE); btC.setVisibility(View.INVISIBLE); btD.setVisibility(View.INVISIBLE); isVisible = true; } } }); }}

⑸ android如何產生隨機數

android產生隨機數的方法:此方法通過把當前時刻長整型數傳給Random對象,讓它產生的值隨著時間而變化。

[java] view plain
Strings = "";
Random ran =new Random(System.currentTimeMillis());
for (inti = 0; i < 10; i++) {
s =s + "\n" + ran.nextInt(100);
}
Toast.makeText(UiTestActivity.this,"Random: \n" + s, Toast.LENGTH_LONG).show();

⑹ 為什麼android中產生不了隨機數

不是android的問題,是你寫法有誤。Math.random()產生的大於等於0,小於1的隨機數,強轉int後變成0,乘以255還是0, 把(int)Math.random()*255改成(int)(Math.random()*255)就可以了。或者就像樓上所說的,用Random類的nextInt(MaxCount)方法也行

⑺ 如何設置android隨機數的上下限

math類的random()方法產生的隨機數是[0,1)看到這里你就明白了把

⑻ 安卓開發中,我想生成一個在a、b之間的隨機數,並且隨機數可以截取到小數點後兩位,請問如何實現謝謝啦

區間[a,b]
Random r=new Random();
double y=r.nextDouble()*(b-a)+a;
DecimalFormat df =new DecimalFormat("#.00");//保留2位小數
System.out.println(df.format(y));

⑼ 如何讓android studio 上的 button 顯示的時候顯示隨機數

1、把手機屏幕分成上下。上下兩部分都採用Linearlayout方式布局 <LinearLayout> <LinearLayout> 上半部分 </LinearyLayout> <LinearLayout> 下半部分 </LinearyLayout> </LinearLayout>2、下半部分LinearLayout高度固定,上半部分LinearyLayout設置layout_weight權重,占滿剩餘屏幕空間 <LinearLayout> <LinearLayout android:layout_height="wrap_content" android:llayout_weight="1"> //設置高度自適應,並且權重為1 </LinearyLayout> <LinearLayout android:layout_height="50px"> //下半部分設置高度固定 </LinearyLayout> </LinearLayout>3、下半部分LinearLayout中添加按鈕,設置android:gravity右對齊。 <LinearLayout android:layout_height="50px" android:gravity="right"> //下半部分設置高度固定 <button andtoid:text="右下角按鈕"/> </LinearyLayout>

⑽ android如何實現產生個隨機數,並計算其中的兩個數

{
int[] x = new int[6];
StringBuilder b = new StringBuilder();
for (int i = 0; i < 10; i++) {
x[i] = (int) (Math.random() * 10);
b.append(x[i]);
}
b.insert(2, ".");
b.append("\n");
char[] c = b.toString().toCharArray();
b.append(c[2]+ "+"+ c[4]+ "="+ (Integer.parseInt(String.valueOf(c[2])) + Integer.parseInt(String.valueOf(c[4]))));
}
});
}
}

閱讀全文

與Android隨機數相關的資料

熱點內容
蘋果怎麼關閉自動排序app 瀏覽:957
國外可以訪問到用什麼伺服器地址 瀏覽:944
揚州前端程序員私活價格 瀏覽:983
視覺演算法程序員該買什麼筆記本 瀏覽:709
鍵盤滑鼠編程 瀏覽:837
linux中修改命令 瀏覽:282
dns伺服器地址怎麼查詢地址 瀏覽:859
php易寶支付介面 瀏覽:606
開源免費oaphp 瀏覽:882
數據加密過程簡述 瀏覽:809
python基礎教程pdf下載 瀏覽:125
如何統計伺服器 瀏覽:746
蘋果和安卓怎麼贈送模組 瀏覽:807
伺服器倒計時怎麼弄 瀏覽:34
excel文件夾更新 瀏覽:437
億點連接app哪裡好 瀏覽:791
java掃碼支付 瀏覽:877
單片機行車記錄儀 瀏覽:393
oppo雲伺服器什麼意思 瀏覽:84
51單片機可以編譯多少公里 瀏覽:27