<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: How can I randomly display blocks of text in a .jsp file?</title>
	<link>http://ask.metafilter.com/57650/How-can-I-randomly-display-blocks-of-text-in-a-jsp-file/</link>
	<description>Comments on Ask MetaFilter post How can I randomly display blocks of text in a .jsp file?</description>
	<pubDate>Sun, 25 Feb 2007 14:02:08 -0800</pubDate>
	<lastBuildDate>Sun, 25 Feb 2007 14:02:08 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: How can I randomly display blocks of text in a .jsp file?</title>
		<link>http://ask.metafilter.com/57650/How-can-I-randomly-display-blocks-of-text-in-a-jsp-file</link>	
		<description>How do I output random blocks of text in a JSP include? I am not in any way a java/jsp programmer. &lt;br /&gt;&lt;br /&gt; I have an application that uses JSP includes to display advertising (Google AdSense) to visitors. Currently, the ads are fairly static in size and content...I&apos;d like to mix it up a little, have different sizes displayed, and occasionally have no ads at all.&lt;br&gt;
&lt;br&gt;
Is there a way to do this just inside the .jsp file? Ideally I&apos;d like to be able to specify what percentage of displays each will get (roughly...doesn&apos;t need to be perfect), like one ad block showing up 10% of the time and another 90%. That&apos;s not a requirement for this though.&lt;br&gt;
&lt;br&gt;
Thanks!</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2007:site.57650</guid>
		<pubDate>Sun, 25 Feb 2007 13:44:56 -0800</pubDate>
		<dc:creator>Kickstart70</dc:creator>
		
			<category>jsp</category>
		
			<category>java</category>
		
			<category>random</category>
		
			<category>ads</category>
		
			<category>advertising</category>
		
			<category>adsense</category>
		
	</item> <item>
		<title>By: delmoi</title>
		<link>http://ask.metafilter.com/57650/How-can-I-randomly-display-blocks-of-text-in-a-jsp-file#866674</link>	
		<description>You can do something like this:&lt;br&gt;
&lt;br&gt;
&amp;lt;%&lt;br&gt;
double d = Math.random();&lt;br&gt;
&lt;br&gt;
if(d &amp;lt; 0.2){%&amp;gt;&lt;b&gt;text block one&lt;/b&gt;&amp;lt;%}&lt;br&gt;
else if(d &amp;lt; 0.4){%&amp;gt;&lt;b&gt;text block 2&lt;/b&gt;%&amp;lt;%}&lt;br&gt;
else {%&amp;gt;&lt;b&gt;text block three&lt;/b&gt;&amp;lt;%}%&amp;gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57650-866674</guid>
		<pubDate>Sun, 25 Feb 2007 14:02:08 -0800</pubDate>
		<dc:creator>delmoi</dc:creator>
	</item><item>
		<title>By: delmoi</title>
		<link>http://ask.metafilter.com/57650/How-can-I-randomly-display-blocks-of-text-in-a-jsp-file#866675</link>	
		<description>Yes, that posted correctly!</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57650-866675</guid>
		<pubDate>Sun, 25 Feb 2007 14:02:19 -0800</pubDate>
		<dc:creator>delmoi</dc:creator>
	</item><item>
		<title>By: delmoi</title>
		<link>http://ask.metafilter.com/57650/How-can-I-randomly-display-blocks-of-text-in-a-jsp-file#866679</link>	
		<description>(Oh wait, there is an extra &quot;%&quot; on the second line.)&lt;br&gt;
&lt;br&gt;
Anyway, the numbers 0.2 and 0.4 control how often each block of text will be printed. The first block will be printed 20% of the time, the second block also 20% of the time (it will only print if d &amp;gt; .2 and d &lt; 0.2) and the last block will print 60% of the time.br&gt;
&lt;br&gt;
Also, that&apos;s just off the top of my head, so I don&apos;t know if the syntax is perfect.&lt;/&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57650-866679</guid>
		<pubDate>Sun, 25 Feb 2007 14:06:49 -0800</pubDate>
		<dc:creator>delmoi</dc:creator>
	</item><item>
		<title>By: comwiz</title>
		<link>http://ask.metafilter.com/57650/How-can-I-randomly-display-blocks-of-text-in-a-jsp-file#866704</link>	
		<description>Here&apos;s one that will work regardless of the number of text blocks you have:&lt;br&gt;
&lt;br&gt;
&lt; %br&gt;
ArrayList l = new ArrayList();&lt;br&gt;
l.add(&quot;First string&quot;);&lt;br&gt;
l.add(&quot;Second string&quot;);&lt;br&gt;
l.add(&quot;Add as many of these as you want&quot;);&lt;br&gt;
&lt;br&gt;
Response.getWriter().print(l.get(Math.random()*l.size()));&lt;/&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57650-866704</guid>
		<pubDate>Sun, 25 Feb 2007 15:04:16 -0800</pubDate>
		<dc:creator>comwiz</dc:creator>
	</item><item>
		<title>By: Civil_Disobedient</title>
		<link>http://ask.metafilter.com/57650/How-can-I-randomly-display-blocks-of-text-in-a-jsp-file#866731</link>	
		<description>Can&apos;t you just do something like:&lt;br&gt;
&lt;br&gt;
&amp;lt;%= &quot;This is some text.&quot; %&amp;gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57650-866731</guid>
		<pubDate>Sun, 25 Feb 2007 15:44:33 -0800</pubDate>
		<dc:creator>Civil_Disobedient</dc:creator>
	</item><item>
		<title>By: Civil_Disobedient</title>
		<link>http://ask.metafilter.com/57650/How-can-I-randomly-display-blocks-of-text-in-a-jsp-file#866732</link>	
		<description>Sorry, missed the &quot;random&quot; part of the question.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57650-866732</guid>
		<pubDate>Sun, 25 Feb 2007 15:45:25 -0800</pubDate>
		<dc:creator>Civil_Disobedient</dc:creator>
	</item><item>
		<title>By: AmbroseChapel</title>
		<link>http://ask.metafilter.com/57650/How-can-I-randomly-display-blocks-of-text-in-a-jsp-file#866752</link>	
		<description>You&apos;re attempting to change how Google AdSense ads display on your page? I&apos;d say that was against their terms of service and therefore a Bad Idea.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57650-866752</guid>
		<pubDate>Sun, 25 Feb 2007 16:09:12 -0800</pubDate>
		<dc:creator>AmbroseChapel</dc:creator>
	</item><item>
		<title>By: Kickstart70</title>
		<link>http://ask.metafilter.com/57650/How-can-I-randomly-display-blocks-of-text-in-a-jsp-file#866912</link>	
		<description>I&apos;m not trying to change the way they display on the page...I just want different size ads to display, and occasionally some self-advertising, which isn&apos;t against the rules. Ie. sometimes I want a 336x280 ad, and sometimes I want a 300x250 ad.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.57650-866912</guid>
		<pubDate>Sun, 25 Feb 2007 19:58:55 -0800</pubDate>
		<dc:creator>Kickstart70</dc:creator>
	</item>
	</channel>
</rss>
