• Post Reply Bookmark Topic Watch Topic
  • New Topic

random a number from {2,4} with % of succes  RSS feed

 
Oleg Glizerin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I wondering how could i randomize a number 2 with 90% and 4 with 10% , with java eclipse?
Please help with syntax


Thanks
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nobody here is going to provide you the answer. At least, I hope not.

First, eclipse would have nothing to do with this. What tool you use to write your code is irrelevant.

Next...how would YOU return a number 2 90% of the time, and 4 10%? All you have is paper, pencils, erasers, and say a 100-sided die?
 
Oleg Glizerin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the thing is that, i about to make game http://git.io/2048 .

i have a two dimensional array that need to get 2 or 4 randomly
maybe some one want to help..
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:

Next...how would YOU return a number 2 90% of the time, and 4 10%? All you have is paper, pencils, erasers, and say a 100-sided die?


Or an urn with 10 balls in it.
 
Oleg Glizerin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stop laugh

im sweat here to solve this ...
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No one's laughing, Oleg. You have two outcomes and a probability for each outcome. Think about real-life situations where those outcomes have those probabilities. For example, suppose you had a drawer with twice as many black socks in it as white socks. If you chose one sock at random, what would the probability of getting a white sock be?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oleg Glizerin wrote:stop laugh

im sweat here to solve this ...

We ARE trying to help you. But the thing about writing software is that before you write a SINGLE line of code, you have to understand the problem. I probably spend about 75% of my time THINKING about the problem, what I want to do, and how to do it, and only 25% writing code.

Writing code is like trying to give a young child directions on how to do something. You can't assume they know anything. You have to be complete and detailed.

so i would suggest you LITERALLY turn off you computer, and start writing down how YOU would return one of those two numbers with those percentage, assuming you have some kind of random number generator like a die with 10 or 100 or 20 sides. Heck, i'll even let you put your own numbers on the die faces. you can write ANY number you want on ANY side.

What would you do to get 2 to show up 9 times (on a 10-sided), and 4 to show up once?
 
Oleg Glizerin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it tooked me a while, but i think i solved that

i used random number between 1-10 for 10 times,
so for each time, if i have the number 1 more than once so, il randomize the 4 number else the 2 number, and where to put them i just used random iRandomed,jRandomed its the indexes, and put into the array,
something like that:
arr[iRandomed][jRandomed] = 4;


thanks guys you pushed me right
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad you figured it out. I have to say, I don't quite follow your logic, but if it works, that's great.

Especially since you figured it out yourself, rather than someone handing it to you.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!