Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com random questions

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 01-06-2004, 04:17 AM PM User | #1 the_bob New Coder   Join Date: Dec 2003 Posts: 85 Thanks: 0 Thanked 0 Times in 0 Posts random questions ok, i've found my huge lack of java scripting knowledge. I have no clue how to use random things. For example, how would you be able to have a list of URLS but only one would pop-up when the site loads? (OnLoad)
 01-06-2004, 04:21 AM PM User | #2 fredmv Regular Coder   Join Date: Jul 2003 Location: Massachusetts Posts: 472 Thanks: 0 Thanked 0 Times in 0 Posts Code: ``````
 01-06-2004, 10:02 AM PM User | #3 Kor Red Devil Mod     Join Date: Apr 2003 Location: Bucharest, ROMANIA Posts: 8,478 Thanks: 58 Thanked 379 Times in 375 Posts Math.random() function generates a random number between 0 and 1 (with more or less digits decimals - usually 16). To obtain a random weighed number between 0 and N you simply multiply the genuine random number with the difference (N-0) and round the result To round you may use different functions such as Math.round - automatic Math.floor - rounds down Math.ceil - rounds up It looks like using Math.floor or Math.ceil is a better choise than Math.round (they give a "more randomized" weighed numbers). Math.floor has another advantage, see below. In your example, you need to obtain a random weighed number between 0 and the lenght of your object type (the number of the objects). Why not lenght-1?... Becouse Math.floor will round for instance 2.99999999999 as 2, and never reach the full 3. So here we are with the explanation for the fredmv's code __________________ KOR Offshore programming -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
 01-06-2004, 12:54 PM PM User | #4 the_bob New Coder   Join Date: Dec 2003 Posts: 85 Thanks: 0 Thanked 0 Times in 0 Posts fred, thanks for the code, thats great! and Kor, Thanks for the explanation. Random numbers are probably one of the most commonly used things in java script. I really appreciate it. but one more question, what does the [CDATA[ in freds code do? Last edited by the_bob; 01-06-2004 at 12:57 PM..
 01-06-2004, 03:17 PM PM User | #5 Kor Red Devil Mod     Join Date: Apr 2003 Location: Bucharest, ROMANIA Posts: 8,478 Thanks: 58 Thanked 379 Times in 375 Posts Maybe fredmv used an editor with an XML validator, as CDATA sections are used to escape blocks of text containing characters which would otherwise be recognized as markup... __________________ KOR Offshore programming -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
 01-06-2004, 09:14 PM PM User | #6 fredmv Regular Coder   Join Date: Jul 2003 Location: Massachusetts Posts: 472 Thanks: 0 Thanked 0 Times in 0 Posts Good explanations Kor (good guess about the XML validator, however, I manually add the CDATA section in scripts or CSS whenever I use embedded code, however, I usually make the code external anyway)... Last edited by fredmv; 01-16-2004 at 08:03 PM..
 01-06-2004, 09:18 PM PM User | #7 the_bob New Coder   Join Date: Dec 2003 Posts: 85 Thanks: 0 Thanked 0 Times in 0 Posts oh, thanks, both of you

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 03:11 PM.