Click here to Skip to main content
       

JavaScript

 
AnswerRe: Browser Back Button Pinmembervinodkumarnie18-Jan-13 22:33 
AnswerRe: Browser Back Button PinmemberDeepak Kr17-Feb-13 22:26 
Generalhow can we set random image in my asp website? Pinmemberkhiladi78631-Dec-12 5:43 
AnswerRe: how can we set random image in my asp website? PinmvpSandeep Mewara4-Jan-13 2:59 
GeneralRe: how can we set random image in my asp website? Pinmemberkhiladi78622-Jan-13 0:52 
GeneralRe: how can we set random image in my asp website? PinmvpSandeep Mewara22-Jan-13 2:34 
Questiongenerate random numbers from specific array Pinmemberaeman29-Dec-12 22:16 
AnswerRe: generate random numbers from specific array PinmvpSandeep Mewara4-Jan-13 3:06 
aeman wrote:
want to generate number from given specific set of numbers

What's the problem with generating random number within a range, see if the random number is not the one you want and then re-get the random number in case it's the one you wanted to avoid?
 
Example;
Random number between 1 to 4.
You wanted one of (1,3,4)
If random number returned is 2, ignore and re-get it.
 
Define a method that takes range start, end and exclude number:
function getRandom(rangeStart, rangeEnd, excludeNo)
{
  var ranNo = GetRandom(rangeStart, rangeEnd);
 
  // ranNo either of: 1, 2, 3, 4
  if(ranNo == excludeNo)
    getRandom(rangeStart, rangeEnd, excludeNo);
  
  return ranNo;
}
Sandeep Mewara
Microsoft ASP.NET MVP 2012 & 2013
 

[My Latest Article(s)]:
How to extend a WPF Textbox to Custom Picker
Server side Delimiters in ASP.NET

AnswerRe: generate random numbers from specific array PinmemberJoe DiNatale4-Jan-13 9:28 
AnswerRe: generate random numbers from specific array PinmemberJohn Y.19-Feb-13 5:47 
Questionaccess info popup page Pinmemberapadana_198928-Dec-12 6:58 
AnswerRe: access info popup page PinmvpSandeep Mewara4-Jan-13 3:13 
AnswerRe: access info popup page Pinmembervinodkumarnie18-Jan-13 22:56 
Questioncontrol other page Pinmemberapadana_198928-Dec-12 6:50 
AnswerRe: control other page Pinmemberaeman29-Dec-12 22:34 
AnswerRe: control other page Pinmemberjkirkerx31-Dec-12 10:34 
QuestionProblem With jQuery AppendTo and Data Attributes [modified] PinmemberAnalogNerd28-Dec-12 3:41 
Questioncss PinmemberSINNAM28-Dec-12 1:32 
AnswerRe: css PinmentorKeith Barrow28-Dec-12 2:33 
Questioncss PinmemberSINNAM28-Dec-12 1:29 
AnswerRe: css PinmvpSandeep Mewara4-Jan-13 3:14 
AnswerFB Connect Javascript Pinmembersasikumar.prs26-Dec-12 23:29 
GeneralRe: FB Connect Javascript Pinmemberkhiladi78631-Dec-12 5:40 
GeneralRe: FB Connect Javascript Pinmemberjkirkerx31-Dec-12 10:36 
AnswerRe: FB Connect Javascript PinmvpSandeep Mewara4-Jan-13 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 22 Oct 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid