פורסם 2004 בנובמבר 921 שנים שלום רציתי לשאול איך אני יוצר מספר רנדומלי בין שני מספרים שהערך יהיה שמור במשתנה INT
פורסם 2004 בנובמבר 921 שנים (Sorry for writing in English, the hebrew alignment makes the following example seem weird) create a new Random object and use the nextInt(int n) method to generate a pseudo-random int between 0 and the parameter n (n isn't included), for example: Random rand = new Random(); int some_int = rand.nextInt(5); some_int will get a random value from one of the follwing: 0,1,2,3,4 hope it helps Roi עריכה: נראה כאילו לכתוב באנגלית לא ממש הועיל, ההודעה מיושרת לימין בלאו הכי
פורסם 2004 בנובמבר 921 שנים בשביל זה יש לך את כפתור ה- שמיישר לשמאל בשביל ליצור מספר "אקראי" בין X ל-Y (כאשר Y>X) אתה צריך Random rand = new Random(); int some_int = X+rand.nextInt(Y-X+1);
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.