Randomness is a common ingredient in computer programming, sometimes for functions you may not become aware of as a user, and sometimes for visible effects. My Android apps use randomness, partly for comic effect, partly to create a more dynamic user experience and partly to stimulate creativity, as I explored in this article: Using Randomness To Stimulate Creativity.
Anyway, the project got me thinking about randomness generally, as it's a fascinating topic. In this article I'll go through the basics of how randomness and random numbers are involved in computer programs.
Uses
Many computer programs use randomness to create dynamic, unpredictable effects. These programs typically use random number generators, which are provided as standard within most of the major languages for desktop and Web programming. For example, a computer game could use a random number generator to choose numbers between 1 and 6 to simulate a dice throw. Shuffle functions in media players sometimes also use random numbers to choose songs and implement play-lists.
The field of security in computer technology also often involves random number generation, particularly when encrypting data.
Random functions within Web development implement various tasks, such as presenting the user with randomly select content from a data source each time they visit a site. This allows developers to maximise on the amount of content they have for a particular Web project. Sites referred to as Web 2.0 often use these functions, particularly when they contain interactive features such as polls.
Random numbers are also often used to prevent caching issues in Web development projects. For example, sites use AJAX functions to fetch new data from a server while the user is viewing a page. In these sites, JavaScript functions within the Web page call PHP or other server side scripts running on the server, which respond with new data, sometimes from a database and formatted in XML. The scripts then write this new data into the Web page. However, developers often encounter problems with caching, in which the user's browser fails to update the content because it has cached it. By passing a random number to the AJAX functions, developers can avoid these caching issues.
Random Number Generators
Programming languages provide standard classes, functions and utilities for random number generation, allowing programmers to generate random values within particular ranges. The first thing to understand about these utilities is that they do not actually generate numbers that are truly random.
By definition, it's not possible to create a computing algorithm, or process, that has random results. Instead, random number generators produce pseudo-random values. Some random number generators are better than others, but in general they aim to produce sequences of numbers that appear random to human observers. The random numbers are normally produced using arithmetic calculations, but most programmers can use them without understanding anything about the underlying process.
Programmers sometimes also need to generate series of non-repeating random numbers. For example, in a typical series of random numbers within a limited range, for example between 1 and 10, you will see the same numbers appearing more than once. To create a series of random numbers without duplicates, programmers need to store the numbers generated in a data structure such as an array, checking each new value against the existing values before accepting the new one into the sequence. These programming activities typically involve control structures such as loops and conditional statements.
Issues
As mentioned above, some random number generators are better than others. Anyone who has tried using them in programming tasks will be well aware of how frustratingly repetitive they can be. As a user, if you've ever felt your music player was repeating the same songs all the time, you might have been right!
Alternatives
The only way to generate truly random numbers is by taking them from naturally random data, which is what services such as the Random.org site do. You can use it to choose lottery numbers, toss coins and pick cards in a more realistic way than most computer programs can produce.
However, for most computer programming purposes a pseudo-random number generator is sufficient and relatively easy to use.
Related Resources:
Tutorials, tips and guides on computing/ information technology for users and developers.
Monday, 27 August 2012
How To Send Mail In PHP
PHP code can send email messages without the need for site administrators to handle them manually. When Web developers build sites and applications, they can opt to send email messages as part of this processing. If you have ever signed up to a website or online service, you may have received an email confirming your account details. These emails are often not sent manually by a person using a standard email client, but by automated scripts. In PHP scripts, you can use sendmail functions to implement this process, which is common in server side scripting.
Purpose
The purpose of sendmail scripts in a PHP site is to send email messages. The sendmail functions allow developers to build email messages in HTML or plain text, then to send these messages to specified recipients.
PHP scripts can set various properties of a message before sending it, including headers, titles, lists of recipients to copy to and the content itself. Often, developers define individual mail scripts dedicated to sending standard email messages for set processes, such as confirming user accounts.
When a PHP script actually sends a message, it can use the mail function. If the recipient chooses to reply to the message, their reply will be sent to the specified "from" address in the script. Using the headers section of the function, developers can include multiple aspects of the message, including MIME and content type.
Syntax
When developers implement sendmail scripts, they use the mail function, which offers a range of options. The following sample code demonstrates calling the function inside a PHP script:
The mail function can receive four parameters, representing the email address to send to, the subject of the message, the message body and any headers the script is setting. This script builds each of the component parts as individual parameters, then passes them to the function when it executes.
Uses
Sites use PHP mail functions for various different purposes. Managing user accounts is a common activity in which sendmail scripts tend to feature, not only for signing users up with new accounts but for account administration actions such as changing passwords and informing users of changes to accounts. Commercial websites also use server side scripts to send automated emails to customers, for example to confirm purchases, payments and dispatching of products.
Considerations
The PHP sendmail functions provide a degree of flexibility for developers. For example, scripts can send HTML formatted mail rather than plain text. However, developers need to consider the email clients and other environmental factors for their users. For example, some HTML email content may not be visible to users on certain platforms. Developers also need to bear in mind the fact that users may be receiving their messages on mobile devices with restricted display and connectivity. For this reason, some developers keep the formatting and content of automated emails as simple as possible.
See Also:
How To: AJAX PHP Functions
How To: JavaScript PHP Function Calls
Purpose
The purpose of sendmail scripts in a PHP site is to send email messages. The sendmail functions allow developers to build email messages in HTML or plain text, then to send these messages to specified recipients.
PHP scripts can set various properties of a message before sending it, including headers, titles, lists of recipients to copy to and the content itself. Often, developers define individual mail scripts dedicated to sending standard email messages for set processes, such as confirming user accounts.
When a PHP script actually sends a message, it can use the mail function. If the recipient chooses to reply to the message, their reply will be sent to the specified "from" address in the script. Using the headers section of the function, developers can include multiple aspects of the message, including MIME and content type.
Syntax
When developers implement sendmail scripts, they use the mail function, which offers a range of options. The following sample code demonstrates calling the function inside a PHP script:
<?php $mail_to = "person@somedomain.com"; $mail_subj = "Hello"; $mail_msg = "This is the content of the email message
"; $mail_frm = "sender@somedomain.com"; $mail_head = "MIME-Version: 1.0\r\n"; $mail_head .= "Content-type: text/html; charset=iso-8859-1"; mail($mail_to, $mail_subj, $mail_msg, $mail_head); ?>
The mail function can receive four parameters, representing the email address to send to, the subject of the message, the message body and any headers the script is setting. This script builds each of the component parts as individual parameters, then passes them to the function when it executes.
Uses
Sites use PHP mail functions for various different purposes. Managing user accounts is a common activity in which sendmail scripts tend to feature, not only for signing users up with new accounts but for account administration actions such as changing passwords and informing users of changes to accounts. Commercial websites also use server side scripts to send automated emails to customers, for example to confirm purchases, payments and dispatching of products.
Considerations
The PHP sendmail functions provide a degree of flexibility for developers. For example, scripts can send HTML formatted mail rather than plain text. However, developers need to consider the email clients and other environmental factors for their users. For example, some HTML email content may not be visible to users on certain platforms. Developers also need to bear in mind the fact that users may be receiving their messages on mobile devices with restricted display and connectivity. For this reason, some developers keep the formatting and content of automated emails as simple as possible.
See Also:
How To: AJAX PHP Functions
How To: JavaScript PHP Function Calls
Sunday, 26 August 2012
Using Randomness To Stimulate Creativity
As part of my Android development projects, I've recently been reading about randomness and how it can help to stimulate the creative process. I've always found randomness interesting and in some cases funny, but it also seems to be a tried and tested creativity technique. In this article I thought I'd run through a few of the concepts and resources I've come across on the subject.
Lots of writers, artists and musicians use randomness to prompt their creative efforts, and computers are offering new ways to implement random (or pseudo-random) processes. Computer programming languages are able to generate random numbers which can then be used to add a level of unpredictability to website or computing application content.
I find randomness really funny, which is why I started learning about this subject, mainly for the purpose of developing my Android Nonsense applications.
Looking for a way to automate nonsense and gibberish, I found a load of funny websites doing similar things. These applications use recognisable language structures with random elements to create comic effect. Here are some of the funnier sites I've found:
Computation
When I studied for my Masters degree in IT, I worked on a software project in which sentences were modelled as templates, with placeholders corresponding to particular parts of speech. For example, the following sentence:
Could be represented using the following placeholders:
Using this idea, you can take a language template and fill words of each part of speech into the placeholder slots randomly. This process could result in the following:
The process here is a little like the game MadLibs, in which you choose words without knowing the sentence (or story) context. My idea was to make the process a little more unpredictable and to automate parts of it, rather than the user having to choose every item.
Language Use
Anyway, it works because of the difference between grammar and semantics. Grammar determines (or describes) the structures that are used within a language to build sentences and clauses. Semantics on the other hand relates to meaning. Chomsky created the following sentence to illustrate the fact that a sentence can make no sense but still be grammatical:
This is the crux of the nonsense sentence. If it was just a series of words it wouldn't be funny, but the fact that our brains recognise it as a sentence structure makes the lack of sense humorous. At the phrasal level, the concept of snowclone is also relevant. This idea relates to a category of language cliches in which a structure has interchangeable elements, for example:
Speakers of a language develop the ability to fill in blanks, an aspect of language learning analysed using Cloze Tests. This tendency to conceive of sentence structures rather than just concrete examples of language seems key to both creativity and understanding.
Creativity
Creativity is a slippery topic. We describe people as creative, generally categorising some people as more creative than others. I don't know if I believe this. I've always tended to "do creative things" but I think it has more to do with habit than nature. In any case, I believe that engaging with creative tasks is not only enjoyable, but also good for mental well-being. For this reason I think it's a good idea to encourage people to stimulate their own creativity, and randomness can aid this process.
Jabberwocky
Lewis Carroll's poem Jabberwocky touches on some related concepts. The poem, an example of Literary Nonsense, uses recognisable structures with nonsense words. Rather than each word being from a known part of speech, these words seem to be from specific parts of speech on account of the sentence structures they appear in. Interestingly, linguistic studies have shown that people often have similar ideas for what the invented words in the poem could mean.
Related Links:
Tech Interpreter Links:
Lots of writers, artists and musicians use randomness to prompt their creative efforts, and computers are offering new ways to implement random (or pseudo-random) processes. Computer programming languages are able to generate random numbers which can then be used to add a level of unpredictability to website or computing application content.
I find randomness really funny, which is why I started learning about this subject, mainly for the purpose of developing my Android Nonsense applications.
Looking for a way to automate nonsense and gibberish, I found a load of funny websites doing similar things. These applications use recognisable language structures with random elements to create comic effect. Here are some of the funnier sites I've found:
- Name Generator Central: Generator Land - This site has loads of great random generators - well worth a browse.
- Daily Mail-o-matic - It's that simple - this gives you a new Daily Mail headline every time you click the button.
- Random Fantasy Novel Title Generator | Fantasy Literature - This page generates fantasy novel titles - it's pretty funny.
- Random Sentence Generator - This simple page demonstrates the sentence generation process.
- Insult Generator: The Insult Project - This site generates funny insults
Computation
When I studied for my Masters degree in IT, I worked on a software project in which sentences were modelled as templates, with placeholders corresponding to particular parts of speech. For example, the following sentence:
The quick brown fox jumps over the lazy dog.
Could be represented using the following placeholders:
Determiner adjective adjective noun verb preposition determiner adjective noun.
Using this idea, you can take a language template and fill words of each part of speech into the placeholder slots randomly. This process could result in the following:
A stupid big car dances on a purple hat.
The process here is a little like the game MadLibs, in which you choose words without knowing the sentence (or story) context. My idea was to make the process a little more unpredictable and to automate parts of it, rather than the user having to choose every item.
Language Use
Anyway, it works because of the difference between grammar and semantics. Grammar determines (or describes) the structures that are used within a language to build sentences and clauses. Semantics on the other hand relates to meaning. Chomsky created the following sentence to illustrate the fact that a sentence can make no sense but still be grammatical:
Colorless green ideas sleep furiously
This is the crux of the nonsense sentence. If it was just a series of words it wouldn't be funny, but the fact that our brains recognise it as a sentence structure makes the lack of sense humorous. At the phrasal level, the concept of snowclone is also relevant. This idea relates to a category of language cliches in which a structure has interchangeable elements, for example:
The ? from Hell
Speakers of a language develop the ability to fill in blanks, an aspect of language learning analysed using Cloze Tests. This tendency to conceive of sentence structures rather than just concrete examples of language seems key to both creativity and understanding.
Creativity
Creativity is a slippery topic. We describe people as creative, generally categorising some people as more creative than others. I don't know if I believe this. I've always tended to "do creative things" but I think it has more to do with habit than nature. In any case, I believe that engaging with creative tasks is not only enjoyable, but also good for mental well-being. For this reason I think it's a good idea to encourage people to stimulate their own creativity, and randomness can aid this process.
Jabberwocky
Lewis Carroll's poem Jabberwocky touches on some related concepts. The poem, an example of Literary Nonsense, uses recognisable structures with nonsense words. Rather than each word being from a known part of speech, these words seem to be from specific parts of speech on account of the sentence structures they appear in. Interestingly, linguistic studies have shown that people often have similar ideas for what the invented words in the poem could mean.
Related Links:
- You are Sooo Random! - Randomness & Creativity Research | Psychology Today - Interesting psychological look at randomness and creativity.
- Random Stimuli - Mycoted - Overview of using random stimuli for creative acts.
- Aleatoricism - Wikipedia - Another creativity technique involving randomness.
- Creativity Games - Brain Training for Creativity and Creative Thinking - Simple games and resources that will improve your creative thinking and problem solving ability.
- Android Development - More info about my Android apps.
Tech Interpreter Links:
The Vital Components in an Effective Web Page
Creating an effective Web page is not always easy. However, if you pay attention to the key elements for success in Web design and development, you should be able to achieve the task. A Web page design will only be successful if the approach is tailored to its purpose. For this reason, developers need to consider the aims and objectives for any website project before and while developing it.
Content
The content of a Web page is the most important aspect of it. All other steps and techniques involved in Web design and development are ultimately aimed at serving the content, presenting it to best effect. The content of your Web page is the reason people will visit it, so it's vital to ensure it is created to a high standard.
For text content, an effective page will only include well written language. For the purposes of SEO (Search Engine Optimisation) your content needs to be structured to perform well in the search engine listings for the key phrases potential visitors will be searching for. Regularly updating page content also helps with SEO performance.
Media
Depending on the purpose of your Web page, you may wish to include multiple different media types, including text, data, images, video, audio and interactive animations using Flash or JavaScript. In a successful Web page, the media items will be selectively chosen to suit the aims of the site. While people now expect a good level of sophistication and engagement with a website, it's also important not to overwhelm your visitors with too much media content or to distract them from their purpose in visiting your site.
Navigation
Navigation in Web design operates both at the level of the website as a whole and within the individual pages. If you have a long page with lots of information and sections within it, you can use HTML anchors to provide shortcuts to these areas, allowing users to focus on those elements they are most interested in. Within an entire site, clear and simple navigation structures using menu elements allow users to achieve their goals quickly and effectively.
Style
Most websites use a combination of HTML, CSS (Cascading Style Sheet) code and images to create an effective visual design. The visual design of a successful Web page will be focused on presenting the content to users, in a way that encourages them to carry out whatever tasks you want them to, while they're on your page. Many developers create design mock-ups using graphic design programs before implementing these in Web page markup and style code.
Interaction
Web pages are not static objects like paper documents. Users expect to be able to interact with a Web page, using their mouse and keyboard. If you are tailoring your website to mobile users you may also need to handle interaction using touchscreen components. Many website elements can be interactive, including user controls such as buttons and menus. Interaction within a successful Web page will also be tailored to website aims, often implemented using JavaScript code.
Links:
Tech Interpreter Links:
Content
The content of a Web page is the most important aspect of it. All other steps and techniques involved in Web design and development are ultimately aimed at serving the content, presenting it to best effect. The content of your Web page is the reason people will visit it, so it's vital to ensure it is created to a high standard.
For text content, an effective page will only include well written language. For the purposes of SEO (Search Engine Optimisation) your content needs to be structured to perform well in the search engine listings for the key phrases potential visitors will be searching for. Regularly updating page content also helps with SEO performance.
Media
Depending on the purpose of your Web page, you may wish to include multiple different media types, including text, data, images, video, audio and interactive animations using Flash or JavaScript. In a successful Web page, the media items will be selectively chosen to suit the aims of the site. While people now expect a good level of sophistication and engagement with a website, it's also important not to overwhelm your visitors with too much media content or to distract them from their purpose in visiting your site.
Navigation
Navigation in Web design operates both at the level of the website as a whole and within the individual pages. If you have a long page with lots of information and sections within it, you can use HTML anchors to provide shortcuts to these areas, allowing users to focus on those elements they are most interested in. Within an entire site, clear and simple navigation structures using menu elements allow users to achieve their goals quickly and effectively.
Style
Most websites use a combination of HTML, CSS (Cascading Style Sheet) code and images to create an effective visual design. The visual design of a successful Web page will be focused on presenting the content to users, in a way that encourages them to carry out whatever tasks you want them to, while they're on your page. Many developers create design mock-ups using graphic design programs before implementing these in Web page markup and style code.
Interaction
Web pages are not static objects like paper documents. Users expect to be able to interact with a Web page, using their mouse and keyboard. If you are tailoring your website to mobile users you may also need to handle interaction using touchscreen components. Many website elements can be interactive, including user controls such as buttons and menus. Interaction within a successful Web page will also be tailored to website aims, often implemented using JavaScript code.
Links:
- Top 10 Mistakes in Web Design (Jakob Nielsen's Alertbox)
- Usability 101: Definition and Fundamentals - What, Why, How (Jakob Nielsen's Alertbox)
- Web Design Tips - Entheos
- 10 Principles Of Effective Web Design - Smashing Magazine
Tech Interpreter Links:
Frequently Asked Questions About Android Apps
Android apps are applications that run on the Android platform. Many devices are now running Android, including smartphones and tablet PCs. The Android operating system provides a number of apps as standard. Additional apps can also be installed and run on an Android device. Android apps cover a wide range of activities, for both work and leisure purposes. Finding and installing apps on and Android device is normally straightforward.
If you're a new Android user and are finding the whole app thing a little baffling, don't worry. The questions here are pretty basic, but might clear a couple of things up for you. The official Android Market/ Google Play Help Centre is also really useful so is well worth a look. Feel free to add more questions in the comments area and I'll do my best to answer them.
What Are Android Apps?
Android apps are standalone applications released by companies and individual developers. When you purchase an Android device such as a smartphone, it will usually have several basic apps already installed on it. These include a Web browser program, an email program and often app versions of Google services such as Gmail. As an Android user, you can also opt to install additional apps on your device whenever you like. The installation process is typically simple.
How Much Do Android Apps Cost?
Some Android apps are free, some are commercial. Many of the commercial apps are supported by advertising, so you may see adverts displayed within those apps while they are running. The commercial apps can have any price chosen by the developer or company who is publishing them. If you purchase and download an Android app that you decide you do not want to keep, you can get a full refund as long as you cancel your purchase within 15 minutes.
What Types Of Android App Are There?
Android apps fall within a wide range of categories, including games, business, communication, education, entertainment, finance, health, fitness, media, productivity, shopping, travel and weather among others. Most apps are designed to enhance the use you get out of your Android device, providing additional functionality on top of the basic operating system functions. The most successful Android apps are easy to use straight away.
Which Devices Can Run Android Apps?
Any device with the Android operating system installed on it can run Android apps. Many devices such as phones, laptops and tablets are now being shipped with Android on them. The operating system is also free, so can be installed on devices at any time. Most Android apps are designed for the unique hardware components you find in a mobile device, with user interaction taking place through touchscreens and buttons.
Where Can I Get Android Apps?
The main source for Android apps is the official Google Play store (formerly Android Market). Google Play is accessible through a Web browser, but is mainly accessed by users through the dedicated Play app on an Android device. Using either the app or browser interface, you can browse through the different app categories, search for specific apps and compare previous user ratings and reviews for any apps you are considering downloading. There are other Android app stores operating online as well.
See also:
Android Things: Android Marketplaces and Directories
How To Uninstall Android Apps | The Tech Interpreter
What Are Android APK Files? | The Tech Interpreter
If you're a new Android user and are finding the whole app thing a little baffling, don't worry. The questions here are pretty basic, but might clear a couple of things up for you. The official Android Market/ Google Play Help Centre is also really useful so is well worth a look. Feel free to add more questions in the comments area and I'll do my best to answer them.
What Are Android Apps?
Android apps are standalone applications released by companies and individual developers. When you purchase an Android device such as a smartphone, it will usually have several basic apps already installed on it. These include a Web browser program, an email program and often app versions of Google services such as Gmail. As an Android user, you can also opt to install additional apps on your device whenever you like. The installation process is typically simple.
How Much Do Android Apps Cost?
Some Android apps are free, some are commercial. Many of the commercial apps are supported by advertising, so you may see adverts displayed within those apps while they are running. The commercial apps can have any price chosen by the developer or company who is publishing them. If you purchase and download an Android app that you decide you do not want to keep, you can get a full refund as long as you cancel your purchase within 15 minutes.
What Types Of Android App Are There?
Android apps fall within a wide range of categories, including games, business, communication, education, entertainment, finance, health, fitness, media, productivity, shopping, travel and weather among others. Most apps are designed to enhance the use you get out of your Android device, providing additional functionality on top of the basic operating system functions. The most successful Android apps are easy to use straight away.
Which Devices Can Run Android Apps?
Any device with the Android operating system installed on it can run Android apps. Many devices such as phones, laptops and tablets are now being shipped with Android on them. The operating system is also free, so can be installed on devices at any time. Most Android apps are designed for the unique hardware components you find in a mobile device, with user interaction taking place through touchscreens and buttons.
Where Can I Get Android Apps?
The main source for Android apps is the official Google Play store (formerly Android Market). Google Play is accessible through a Web browser, but is mainly accessed by users through the dedicated Play app on an Android device. Using either the app or browser interface, you can browse through the different app categories, search for specific apps and compare previous user ratings and reviews for any apps you are considering downloading. There are other Android app stores operating online as well.
See also:
Android Things: Android Marketplaces and Directories
How To Uninstall Android Apps | The Tech Interpreter
What Are Android APK Files? | The Tech Interpreter
Subscribe to:
Posts (Atom)