ASP.NET random sentence on load

PHTech

Senior Member
Joined
Aug 21, 2006
Messages
588
Reaction score
0
Location
Witbank
Hi there...

Does anybody knows a SIMPLE random sentence generator? Each time the page loads, it should display a different sentence...

Thanx...!
 
firstly you need something like a wordlist, from where the sentence can be read and then fed to the page.
 
Code:
'Sent
Sent(0) = "Sentence 1"
Sent(1) = "Sentence 2"
Sent(2) = "Sentence 3"
Sent(3) = "Sentence 4"

'Pick Random Array Offsets
Randomize Timer
SO = Int(UBound(Sent) * Rnd + LBound(Sent))
MsgBox "" & Sent(SO)

Erase Sent

Code is not tested as I dont realy code in asp, but basicly it just choose a random sentence out of the array Sent.
 
I have managed to find this JavaScript which works 100%... Thanx for your replies...!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Random Sentence w/Cookie script - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<span id="theS"></span>
<script type="text/javascript">
/* Random Sentence w/Cookie script
* All credits must remain for legal use */

// Cookie code from: http://www.quirksmode.org/js/cookies.html
function createCookie(name,value) {
document.cookie = name+"="+value+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca;
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function rs(){ // Random Sentence on Refresh w/Cookie - jscheuer1 - http://www.dynamicdrive.com/forums
var s=[
'Hey there',
'How there',
'Hey now',
'Way home',
'All now'];
s.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
var sn=readCookie('sen')&&readCookie('sen')==s[0]? s[1] : s[0];
document.getElementById('theS').innerHTML=sn;
createCookie('sen',sn)
}
rs();
</script>
</body>
</html>
 
You do realise it would have been a lot easier if you put them in a mysql database and just called the rand query and it would have randomly called you a row out the db. less lines than the javascript.

I hate javascript. Infact i hate anything that requires the client to have support for. Server side is much better. :(
 
You do realise it would have been a lot easier if you put them in a mysql database and just called the rand query and it would have randomly called you a row out the db. less lines than the javascript.

I hate javascript. Infact i hate anything that requires the client to have support for. Server side is much better. :(

js has its place, but lol it its not neat to write block of code that could have been server to client side rather.
 
indeed. I also despise asp.net cos it seems to rely heavily on javascript to get anything done. Ms need to pull up their socks with that. To each his own i suppose
 
indeed. I also despise asp.net cos it seems to rely heavily on javascript to get anything done. Ms need to pull up their socks with that. To each his own i suppose

You are very wrong there. ASP.NET does not rely on JS that much. There are many ways of getting past the whole __doPostBack() thing and write a whole site without a single line of JS.
 
True, but is it really worth all the effort? I suppose you could just use get and post. I'm just not fond of ASP.net :(
 
Lol. i grew up on php. asp.net is not my cup of tea. how ever the dot net framework is very awesome indeed. just not for web.
 
just not for web.
Again you are very wrong. ASP.NET is very powerful and scalable, especially if you know what you are doing. Forget about just using web forms. The true power of .NET lies in its ability to build scalable multi-tier applications. XML and XSLT give you a powerful alternative to "hard coding" web forms and the new ASP.NET MVC framework also opens up the possibilities of discarding traditional web forms.

I might be sightly biased though, seeing as "I grew up on ASP.NET"... :p
 
i suggest

GetRoom(FarligOpptreden,monkeeh);

:D
 
i suggest

GetRoom(FarligOpptreden,monkeeh);

:D

Your implementation is limited in the sense that it implies that only 2 participants can be in a room at any point in time. A better solution would be to define the method to accept a collection / array of Participants, which would make for a more flexible and scalable implementation.

So you could define a Participant object with properties for Id and Name, as well as a collection of Participants (making sure to implement the IEnumerable interface, of course) and implement the solution as follows:

Code:
Participants theParticipants = new Participants();
theParticipants.Add(new Participant("FarligOpptreden",26932));
theParticipants.Add(new Participant("monkeeh",7543));
GetRoom(theParticipants);

Another thing, what is the return value of your method GetRoom()? Is it just void? And what happens to the participants afterwards? Or should they be passed in by reference? So many questions...
 
Your implementation is limited in the sense that it implies that only 2 participants can be in a room at any point in time. A better solution would be to define the method to accept a collection / array of Participants, which would make for a more flexible and scalable implementation.

So you could define a Participant object with properties for Id and Name, as well as a collection of Participants (making sure to implement the IEnumerable interface, of course) and implement the solution as follows:

Code:
Participants theParticipants = new Participants();
theParticipants.Add(new Participant("FarligOpptreden",26932));
theParticipants.Add(new Participant("monkeeh",7543));
GetRoom(theParticipants);
rofl

Another thing, what is the return value of your method GetRoom()? Is it just void? And what happens to the participants afterwards? Or should they be passed in by reference? So many questions...

they stay in the void :eek:, but they don't know that beforehand :D
 
they stay in the void :eek:, but they don't know that beforehand :D
Nonsense. If the return type for the method is void and the objects aren't passed by reference, they'll know they are going into a void and won't be returning. Well, I'm speaking for myself, of course. Apparently monkeeh isn't too acquainted with .NET, so he might end up stuck in the void... ;)
 
Top
Sign up to the MyBroadband newsletter
X