Is It Possible To Weigh Random Numbers?

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

Is It Possible To Weigh Random Numbers?

beeseven
I'm making an RPG so I need to use a lot of random numbers. Right now I'm thinking about stat increases after level-ups. I want to write a method that does something like "return a random number from 0 to 4 inclusive, but make it most likely to be 1 or 2." Does anybody know how I could go about implementing something like that?

Reply

delivi
I cannot understand what you need. Pleas kindly explain it.

Reply

beeseven
I thought I did. I want something that will return a random number in a certain range that can be any number in that range but will usually be in a smaller range. For example, using the numbers above (0-5 inclusive but most likely 1 or 2), ten numbers returned might be:

2, 1, 1, 3, 2, 0, 1, 5, 2, 1

Seven of those are 1 or 2, and the other three are other numbers in the 0-5 range.

Reply

rvalkass
Well one choice would be to generate a random number from say, 1 to 100. Then if you want a 75% chance of it being 1 or 2 then say that if the first number is less than 75, generate a random number from 1 to 2, otherwise, generate one from 3 to 4. Its probably not the most efficient way of doing it, but it should work.

Reply

peroim
It's not that hard to make that! I'll explain it to you using a simple code:

CODE

var numarray = new Array(1, 1, 1, 2, 2, 2, 3, 4);
/* This is the array of possible values. The more times you use a number, the more times it will return. */
var rand = Math.round(Math.random()*(numarray.length-1));
/* This code creates a random number between 0 and (numarray.length-1). */
var num = numarray[rand];
/* This piece will take a value out of the array, based on the random number of the second line of code. */


And this will always return one of the values you want! Of course, you speak of a function that returns a value, so it will be more like this:

CODE

function randomNumber(){
var numarray = new Array(1, 1, 1, 2, 2, 2, 3, 4);
var rand = Math.round(Math.random()*(numarray.length-1));
var num = numarray[rand];
return num;
}

 

 

 


Reply

beeseven
Yeah that occurred to me a while after I made this topic, but it's just not as cool as it could be.

Reply

augyd
-

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : weigh random numbers

  1. How Do I Enter Only Numbers In A Form? - (2)



Looking for weigh, random, numbers

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for weigh, random, numbers

*MORE FROM TRAP17.COM*
advertisement



Is It Possible To Weigh Random Numbers?



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE