[Fun] Lorem Ipsum generator

Discuss and share scripts and script files...
SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

[Fun] Lorem Ipsum generator

Post by SammaySarkar » 18 Mar 2015 19:11

Lorem ipsum aliquam adipiscing id id libero at, laoreet dis aptent sed rhoncus id magnis posuere rutrum mollis sed lorem Vivamus pretium pellentesque nisl pellentesque In? tortor suscipit nibh ipsum commodo nostra velit Curae Duis, at Cras sagittis non Curabitur urna laoreet nisi id sed aliquam egestas habitasse nec venenatis? rutrum elit Sed dui mus Nullam Cras Curabitur ornare mi lorem metus Suspendisse id pulvinar pulvinar sed elementum ligula Duis varius finibus pharetra eget dictum elit ipsum Quisque laoreet! orci Vestibulum diam suscipit Pellentesque amet quis sed Suspendisse, Donec nec ante id erat amet leo semper.
That was generated by XYplorer! :biggrin:

Why, you ask? Why not?

The generator is intended to be used as a function re-useable subscript. Directions inside.
Source:

Code: Select all

FUNCTION lipsumGen($lipsumLen, $lipsumText, $separator=" ") {
 /* a simple lorem ipsum generator. "Why?" you ask? Why Not? [http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=13644]
 ** **Parameters**
 **   $lipsumLen    defines how many words generated text should have. Defaults to 20.
 **   $lipsumText   a custom word source. If it points to an existing file, words are read from that file.
 **   $Separator    separator between words. Defaults to space. Default $lipsumText is separated by the same.
 ** **Return**
 **   the generated text string.
 ** **Notes**
 **   Some punctuation characters are stripped from words, and others added
 **   $lipsumText should not have <crlf> .
 */

 $lipsumGen = '';
 if !isset($lipsumLen) || ($lipsumLen == "") || (regexmatches($lipsumLen, '[^\d]+')!='') {$lipsumLen = '20';} // reset
 if ($lipsumText != ''){
   $lipsum = (exists($lipsumText) == 1) ? readfile($lipsumText) : ($lipsumText);
 }
 else {
  // the default standard lorem ipsum text. Should not include CRLF.  
  $lipsum = trim(<<<#Lipsum^^^
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer et pharetra sapien. Nam ut velit mollis, vehicula nunc ornare, ultricies ex. Nam a posuere sem, quis mattis ante. Donec pulvinar mauris eros, in tincidunt tortor blandit sed. Suspendisse felis nunc, elementum et lobortis sed, pellentesque lacinia nibh. Cras mattis interdum libero. Proin non nunc mattis, luctus urna nec, laoreet erat. Proin porttitor sed turpis eget pulvinar. Quisque semper a enim id consectetur. In nec ipsum dictum, auctor leo in, suscipit velit. Sed rutrum a mauris sit amet porta. Phasellus pretium pharetra nibh. Nunc id enim nec magna venenatis suscipit ac pellentesque sem. Nunc ut tristique quam. Suspendisse felis mauris, pulvinar vel sagittis sed, varius a nisl. Suspendisse ac neque id erat volutpat molestie eget eu lorem. Cras congue, tortor at auctor consequat, magna ligula bibendum augue, quis accumsan turpis sapien ut mauris. Suspendisse ex justo, aliquet vitae odio non, aliquet vestibulum tellus. Donec in faucibus dui. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nullam ut orci vehicula, laoreet nunc sed, mattis odio. Etiam quis velit nec nibh semper faucibus. Maecenas elit orci, gravida sit amet tempor quis, sodales ultricies dui. Donec condimentum massa posuere, varius tellus ornare, ultrices ante. Vivamus rutrum lacus at nisl sagittis blandit. Vivamus enim erat, dapibus blandit nisl a, vulputate fringilla lorem. Duis at suscipit lacus. In hac habitasse platea dictumst. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse id diam iaculis, pellentesque nisi ut, cursus tortor. Sed suscipit lectus vitae nisl vestibulum, ac eleifend orci lobortis. Pellentesque egestas non purus at aliquam. Curabitur vitae scelerisque justo. Nullam pretium dolor a tincidunt lacinia. Duis ac porttitor mi. Maecenas vulputate ultricies feugiat. Suspendisse potenti. Nullam quam tortor, placerat in sollicitudin sed, pulvinar ac sapien. Nam pretium consectetur augue, et finibus metus rutrum eget. Cras eget risus ornare, facilisis enim a, pellentesque nunc. Duis at pretium nibh. Sed a arcu nec metus suscipit molestie in id enim. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus bibendum tortor tortor, vitae porttitor lacus tincidunt eget. Proin vestibulum velit non venenatis rhoncus. Vestibulum sed lectus nec neque porta dapibus. Vivamus accumsan suscipit dui, at tempor leo aliquam eget. Nullam aliquet a sapien et mollis. Pellentesque bibendum commodo quam, eget consectetur purus tincidunt aliquam. Sed a ornare lorem. Sed luctus pulvinar ultricies.#Lipsum^^^,
            "<tab> ", 'L');
 }

 $t = gettoken($lipsum, 'count', $separator); // total words
 while ($c++ < $lipsumLen){
  $word = '';
  while ($word == ''){$word = replace(gettoken($lipsum, rand(1, $t), $separator), <crlf>, '');} //take no crlfs

 ////strip some punctuations from words, and sprinkle some ...
  $puncs = ', ; . ! ?'; $punc = '';
  if (rand(0, 13) Like '[71]') { // pick a random punc from $puncs
   $randP = rand(1, gettoken($puncs, 'count', ' ')); 
   $punc  = gettoken($puncs, $randP, ' ');
  }
  $word  = replacelist($word, $puncs, '', ' ');   //remove present puncs from picked word...
  $lipsumGen = $lipsumGen . ' ' . $word . $punc;  //...and add word + our random punctuation
  
 ////...or uncomment to just add a plain random word, along with any punctuation. :(
  // $lipsumGen = $lipsumGen . ' '. gettoken($lipsum, rand(1, $t), ' '); 
 }

 $lipsumGen = trim($lipsumGen, "<crlf> ");
 if (substr($lipsumGen, -1) != '.') { $lipsumGen = $lipsumGen . '.'; }


 return $lipsumGen;
}
[/size]

Examples:
Assuming the function is saved in <xyscripts>\inc\lipsumgen.xyi)

Code: Select all

INCLUDE "inc\lipsumgen.xyi";

"LipsumGen Length Demo"
  text lipsumgen(1200);

"LipsumGen Paragraphs Demo"
  $input = input('Input: paragraph count|*max* wordcount of each paragraph (minimum is 10)',
                 'eg, enter "3|500" for 3 paragraphs with about 500 words each','3|500','s');
  $paragraphCount = trim(gettoken($input, 1, '|'),' ') * 1;
  $maxWordsCount  = trim(gettoken($input, 2, '|'),' ') * 1;
  //$maxWordsCount = ($maxWordsCount < 10) ? 10 : $maxWordsCount;
  $lipsumGen = '';
  while ($paragraphCount-- > 0){
    $lipsumLen = rand(ceil($maxWordsCount*80/100), $maxWordsCount); //randomize wordcount
    $lipsumGen = $lipsumGen.lipsumgen($lipsumLen).<crlf 2>;
  }
  $lipsumGen = trim($lipsumGen, '<crlf>', 'R');
  text $lipsumGen;

Another great use may be when you convert it to an alias with arguments, then do,say, @lipsum 34 and the result gets copied to clipboard!
Here's an example alias (paste this right into the addressbar and press ENTER)

Code: Select all

@lipsum=::load readfile("<xyscripts>\lipsumGen.xyi")."<crlf>text lipsumGen(<@1>)",,s;
and here's an example alias usage (again, paste this right into the addressbar and press ENTER)

Code: Select all

@lipsum 25

[edit: converted to a user-defined function][edit: cleanup+slightspeedup]
Attachments
LipsumGen.xyi.xys
User-Defined Function LipsumGen()
Generate filler lorem ipsum text
(4.43 KiB) Downloaded 102 times
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Stef123

Re: [Fun] Lorem Ipsum generator

Post by Stef123 » 18 Mar 2015 20:46

Hehe - didn't know you could do stuff like that with XY :titter:
Thanks for those links (deviantart etc) in the other thread, don't want to clutter it with off-topic detours.

Ipsum Bacon kills me, dishes out a heartier meal than the regular ipsum. More filling. too. :kidding:

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: [Fun] Lorem Ipsum generator

Post by SammaySarkar » 18 Mar 2015 21:06

:mrgreen:

just serve a long line of food to $lipsum !
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: [Fun] Lorem Ipsum generator

Post by SammaySarkar » 20 Mar 2015 18:30

whoops. There was a silly mistake. Would not generate text would not have the desired length ($lipsumLen). Fixed now.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

aurumdigitus
Posts: 1039
Joined: 30 May 2008 21:02
Location: Lake Erie

Re: [Fun] Lorem Ipsum generator

Post by aurumdigitus » 20 Mar 2015 19:13

Surely this script must have a "raison d'être". It is just not immediately obvious what it is.

How about it simply demonstrates a proof of concept? You never know what mighty tree might grow from a seed is such as this!

:wink:

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: [Fun] Lorem Ipsum generator

Post by SammaySarkar » 21 Mar 2015 06:24

This does have a really practical use: generating randomized dummy filler text! otherwise... some things just have no use.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

PeterH
Posts: 2588
Joined: 21 Nov 2005 20:39
Location: Germany

Re: [Fun] Lorem Ipsum generator

Post by PeterH » 21 Mar 2015 12:10

Sometimes you create things, and later on you have to learn they are of no use.

So I think it's an advantage to create a thing that's planned to be of no use, isn't it? :ugeek:

:wink:

edit: I forgot to say that it can be fun :lol:
W7(x64) SP1 German
( +WXP SP3 )

aurumdigitus
Posts: 1039
Joined: 30 May 2008 21:02
Location: Lake Erie

Re: [Fun] Lorem Ipsum generator

Post by aurumdigitus » 23 Mar 2015 14:51

@ SammaySarkar -Being a bit giddy on the occasion of the first day of spring I was only having a little fun with you.

Actually, have found your script to be quite useful. As one who frequently needs the use of padding when constructing templates for documents have been using http://www.ipsum.com a long time. Now your work has been made a custom toolbar button.

Having had Latin in both high school and as an undergraduate (for fun and as time permits) will replace the random words in the script was sections from Cicero's Verrine Orations and Julius Caesar's Gaelic commentaries.

As far as being useful is concerned am reminded of what Charles Darwin wrote in the preface to his famous book the Origin Of Species, " To see what every man has seen; to think what no man has thought". :)

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: [Fun] Lorem Ipsum generator

Post by SammaySarkar » 23 Mar 2015 15:03

Great! :)

[btw, I've edited the script after your last post.]
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: [Fun] Lorem Ipsum generator

Post by SkyFrontier » 10 Jun 2015 02:51

My take on dummy texts.
-generates larger chunks of randomized text, under blocks having randomized length.
Thanks, Sammay! :tup:
Attachments
LoremIpsumGenerator_v2_by_SF.xys
(3.86 KiB) Downloaded 99 times
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Stef123

Re: [Fun] Lorem Ipsum generator

Post by Stef123 » 10 Jun 2015 05:52

Thanks Sky,
nice improvement to get several paragraphs in varying lengths.
how do I get rid of that first blank up front of every paragraph?

highend
Posts: 9065
Joined: 06 Feb 2011 00:33

Re: [Fun] Lorem Ipsum generator

Post by highend » 10 Jun 2015 08:55

Replace:

Code: Select all

$re = trim($re, "  ")
with

Code: Select all

$re = regexreplace($re, "^\ +");
and remove the leading space in the last line from
" $re" -> "$re"
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Stef123

Re: [Fun] Lorem Ipsum generator

Post by Stef123 » 10 Jun 2015 10:11

:shock:
Thank you highend. :tup:
This turns out much more complicated than I'd have imagined. Glad I gave up early after my first few attempts failed.

highend
Posts: 9065
Joined: 06 Feb 2011 00:33

Re: [Fun] Lorem Ipsum generator

Post by highend » 10 Jun 2015 10:23

Btw, my approach:

You define exactly how many paragraphs you want (first value) and if you like, how many sentences each of them should have. If you omit the second value, a random value (5-35) is chosen. First and second value must be separated by a comma! Main difference: All sentences are selected randomly!
Less code, probably a bit easier to understand.
LoremIpsumGenerator_by_Highend.zip
(1.75 KiB) Downloaded 101 times
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Stef123

Re: [Fun] Lorem Ipsum generator

Post by Stef123 » 10 Jun 2015 11:18

Very interesting take on it, highend,
I probably don't fully understand it, my second value seems to feed it some kind of randomizer to work with, but actually, that's a nice twist on it, too. The generated paragraphs vary in number and lenghts - that do not match the values entered, but again, interesting in its own way, need to explore it further some other time.

Ed:
Got it, it's a comma I have to put in between :oops: not a blank

Post Reply