"Mr Branding" is a blog based on RSS for everything related to website branding and website design, it collects its posts from many sites in order to facilitate the updating to the latest technology.
To suggest any source, please contact me: Taha.baba@consultant.com
Monday, January 23, 2017
Mathematical Modules in Python: Random
Randomness is all around us. When you flip a coin or roll a die, you can never be sure of the final outcome. This unpredictability has a lot of applications like determining the winners of a lucky draw or generating test cases for an experiment with random values produced based on an algorithm.
Keeping this usefulness in mind, Python has provided us with the random module. You can use it in games to spawn enemies randomly or to shuffle the elements in a list.
How Does Random Work?
Nearly all of the functions in this module depend on the basic random() function, which will generate a random float greater than or equal to zero and less than one. Python uses the Mersenne Twister to generate the floats. It produces 53-bit precision floats with a period of 2**19937-1. It is actually the most widely used general-purpose pseudo-random number generator.
Sometimes, you want the random number generator to reproduce the sequence of numbers it created the first time. This can be achieved by providing the same seed value both times to the generator using the seed(s, version) function. If the parameter s is omitted, the generator will use the current system time to generate the numbers. Here is an example:
import random random.seed(100) random.random() # returns 0.1456692551041303 random.random() # returns 0.45492700451402135
Keep in mind that unlike a coin flip, the module generates pseudo-random numbers which are completely deterministic, so it is not suitable for cryptographic purposes.
Generating Random Integers
The module has two different functions for generating random integers. You can use randrange(a) to generate a random whole number smaller than a.
Similarly, you can use randrange(a, b[,step]) to generate a random number from range(a, b, step). For example, using random.randrange(0, 100, 3) will only return those numbers between 0 and 100 which are also divisible by 3.
If you know both the lower and upper limit between which you want to generate the numbers, you can use a simpler and more intuitive function called randint(a, b). It is simply an alias for randrange(a, b+1).
import random random.randrange(100) # returns 65 random.randrange(100) # returns 98 random.randrange(0, 100, 3) # returns 33 random.randrange(0, 100, 3) # returns 75 random.randint(1,6) # returns 4 random.randint(1,6) # returns 6
Functions for Sequences
To select a random element from a given non-empty sequence, you can use the choice(seq) function. With randint(), you are limited to a selection of numbers from a given range. The choice(seq) function allows you choose a number from any sequence you want.
Another good thing about this function is that it is not limited to just numbers. It can select any type of element randomly from a sequence. For example, the name of the winner of a lucky draw among five different people, provided as a string, can be determined using this function easily.
If you want to shuffle a sequence instead of selecting a random element from it, you can use the shuffle(seq) function. This will result in an in place shuffling of the sequence. For a sequence with just 10(n) elements, there can be a total 3628800(n!) different arrangements. With a larger sequence, the number of possible permutations will be even higher—this implies that the function can never generate all the permutations of a large sequence.
Let's say you have to pick 50 students from a group of 100 students to go on a trip.
At this point, you may be tempted use the choice(seq) function. The problem is that you will have to call it about 50 times in the best case scenario where it does not choose the same student again.
A better solution is to use the sample(seq, k) function. It will return a list of k unique elements from the given sequence. The original sequence is left unchanged. The elements in the resulting list will be in selection order. If k is greater than the number of elements in the sequence itself, a ValueError will be raised.
import random ids = [1, 8, 10, 12, 15, 17, 25] random.choice(ids) # returns 8 random.choice(ids) # returns 15 names = ['Tom', 'Harry', 'Andrew', 'Robert'] random.choice(names) # returns Tom random.choice(names) # returns Robert random.shuffle(names) names # returns ['Robert', 'Andrew', 'Tom', 'Harry'] random.sample(names, 2) # returns ['Andrew', 'Robert'] random.sample(names, 2) # returns ['Tom', 'Robert'] names # returns ['Robert', 'Andrew', 'Tom', 'Harry']
As you can see, shuffle(seq) modified the original list, but sample(seq, k) kept it intact.
Generating Random Floats
In this section, you will learn about functions that can be used to generate random numbers based on specific real-value distributions. The parameters of most of these functions are named after the corresponding variable in that distribution's actual equation.
When you just want a number between 0 and 1, you can use the random() function. If you want the number to be in a specific range, you can use the uniform(a, b) function with a and b as the lower and higher limits respectively.
Let's say you need to generate a random number between low and high such that it has a higher probability of lying in the vicinity of another number mode. You can do this with the triangular(low, high, mode) function. The low and high values will be 0 and 1 by default. Similarly, the mode value defaults to the mid-point of the low and high value, resulting in a symmetrical distribution.
There are a lot of other functions as well to generate random numbers based on different distributions. As an example, you can use normalvariate(mu, sigma) to generate a random number based on a normal distribution, with mu as mean and sigma as standard deviation.
import random random.random() # returns 0.8053547502449923 random.random() # returns 0.05966180559620815 random.uniform(1, 20) # returns 11.970525425108205 random.uniform(1, 20) # returns 7.731292430291898 random.triangular(1, 100, 80) # returns 42.328674062298816 random.triangular(1, 100, 80) # returns 73.54693076132074
Weighted Probabilities
As we just saw, it is possible to generate random numbers with uniform distribution as well as triangular or normal distribution. Even in a finite range like 0 to 100, there are an infinite number of floats that can be generated. What if there is a finite set of elements and you want to add more weight to some specific values while selecting a random number? This situation is common in lottery systems where numbers with little reward are given a high weighting.
If it is acceptable for your application to have weights that are integer values, you can create a list of elements whose frequency depends on their weight. You can then use the choice(seq) function to select an element from this weighted list randomly. Here is an example showing the selection of a prize amount randomly.
import random
w_prizes = [('$1', 300), ('$2', 50), ('$10', 5), ('$100', 1)]
prize_list = [prize for prize, weight in w_prizes for i in range(weight)]
random.choice(prize_list)
# returns '$1'
In my case, it took ten trials to get a $2 prize chosen from the list. The chances of getting a $100 prize would be much lower. Similarly, you can also add bias to other such programs.
Final Thoughts
This module can be useful in a lot of situations like shuffling the questions in an assignment or generating random usernames or passwords for your users by using the shuffle() function. You can also generate random numbers uniformly as well as give weighting to numbers in a specific range. In our next tutorial, we will be using the functions from this module to generate random data for statistical analysis.
Do you have some interesting applications of random number generators in mind that can be useful to fellow readers? Let us know in the comments.
by Monty Shokeen via Envato Tuts+ Code
10 Quick Tips to tighten your Landing Page design
I’m proud to say One Page Love features over 6k websites now. To add more value I write a micro-review with feedback on each website featured.
Unfortunately, with the continuous push to increase quality, not all submissions get in. These 10 tips below form the most common feedback I give users to help improve their Landing Page design.
What (exactly) is a Landing Page?
Before we begin, let’s define a few things…
A Landing Page aims to provide the perfect (read minimum) amount of information for a user to make a decision and act upon it. This website page is often seen as a standalone long-scrolling One Page website and has no additional pages (like about, services, contact).
The purpose of a Landing Page is to encourage user interaction (sign up, download or sale) without the user clicking to other pages. This successful interaction is also known as a conversion.
This article can be your checklist to communicate in the clearest way possible, cut through clutter and in-turn, increase those sweet sweet conversions.
eBook Format
If you really enjoy the article and want to support – I’ve added all these tips into a neat eBook (pay what you want) in PDF and ePub (iBooks) format.
I also threw in a couple bonus tips on “Deconstructing your About paragraph” and “Understanding Storytelling in Landing Pages”. At the back is a printable 20-point ‘Design Checklist’ to ensure your Landing Page is watertight.
The bulk of the eBook is all below but the contribution helps keep One Page Love ad free:)
Hope you find value in the article!
Much love,
Rob
ps. the awesome cover illustration is by Karolis Strautniekas
“The ability to simplify means to eliminate the unnecessary so that the necessary may speak.” ~ Hans Hofman
Tip 1 – Keep brand capitalization consistent
So often overlooked, inconsistencies in your brand name affects first impression and can even create confusion. Here are the possible variations I’ve seen using “One Page Love”:
- One Page Love (correct)
- Onepagelove
- ONEPAGELOVE
- onepagelove
- one page love
- One-Page Love
- Onepage Love
Here are some popular ones:
- WordPress (1 word, 2 capital letters)
- MailChimp (1 word, 2 capital letters)
- Stack Overflow (2 words)
- Facebook (1 word)
Avoid ALL CAPS if you can but choose one and stick with it.
Tip: Visit your live Landing Page, use your browser in-page search and try find all possible variations of your brand name.
Tip 2 – Don’t neglect Retina optimization
If anything, you absolutely must have a Retina-optimized logo. A “pixelated” logo affects first impressions like you won’t believe.
This basically means your logo needs to be double the size on Retina screens or must be in Vector format ie. SVG
Note the “pixelated” logo on the left and crisp Retina-optimized logo to the right:
Next on priority list would be app or website screenshots, the crisper the better first impression:
Lastly is your big imagery:
Tip: Use ImageOptim for optimizing bigger, rich color images. It’s debatable what the ideal page load size is, but optimizing everything is always good practice.
Useful links:
- PNG to SVG resources – a link filled article on Stack Overflow
- IconFinder – tons of free vector social icons
- Ready-To-Use SVG icons – copy & paste resource
- Hero Patterns – repeatable SVG background patterns
- Textures.js – SVG patterns for data visualization (infographics)
Tip 3 – More padding and then some
The majority of users are going to skim your content. If you bundle everything together they are going to skim even more.
81 percent of people only skim the content they read online. Usability expert Jakob Nielsen reports the average user reads at most 20 to 28 percent of words during an average visit. (source)
Whitespace is often technically referred to as negative space. But it’s really the breathing room for your content and also for the user. This slows them down and increases focus.
We talk about “graceful downgrading” of padding from desktop to mobile (eg. 40px desktop, 20px mobile) but what about “graceful upgrading” to huge monitors? What a delight it is to see optimization with generous padding (along with bigger fonts) on larger resolutions:
Tip: If you’re questioning if you should increase padding, you should probably double it.
Tip: Increase padding but still stick to a grid.
Tip: Reverse engineer your padding allowances by working around the perfect line length (characters per line) based on your font size.
Useful links:
- Websites with good whitespace – for inspiration
- Golden Ratio Typography Calculator – optimize characters per line
- How to Tune Typography Based on Characters Per Line – by Personified
- 1200px Grid System – in PSD, AI & CSS
- All about Grid systems – by Rachel Shillcock
Tip 4 – Consistent vertical spacing
So we covered grids (commonly used for horizontal padding) but we often overlook vertical spacing in a Landing Page.
It can get pretty technical with things like Vertical Rhythms and Baseline Grids but what about consistent section spacing and padding between elements?
Here is a classic long-scrolling Landing Page I threw together with “sections” of content:
Now note the consistency in vertical spacing and secondly how the smaller gaps are half the ratio of the bigger gaps:
Tip: Keep spacing within consistent ratios. Example: if we set 50px button, then set section title bottom margins also at 50px and section diver spacing at 100px. Consistency is key.
Useful links:
- 4 Simple Steps to Vertical Rhythm – by Shelly Wilson
- How to Create Vertical Rhythm and Harmony – by Carrie Cousins
- Designing Faster with a Baseline Grid – by Pierre Marly
- CSS Baseline: The Good, The Bad And The Ugly – by Espen Brunborg
- Basehold.it – JavaScript-free, baseline grid overlay for your designs
- Modular Scale – Size your type in a more meaningful way
- Type Scale – A visual calculator to test your type
Tip 5 – Less images, better images
It can take one good image to completely change the emotion of your user. Unfortunately, same goes for one bad image.
“Simplicity means the achievement of maximum effect with minimum means.” ~ Dr. Koichi Kawanaite
Good imagery builds trust. Trust leads to conversions.
Spend the money. Get a photoshoot of your team, your product, your food. The ROI on a photoshoot is always guaranteed.
Tip: Once you have a good selection, ask yourself if each image truly captures your story or compliments your brand. Eliminate everything non-essential.
Useful links:
- Unsplash – Free (do whatever you want) high-res photos
- Beautiful Team Images – for inspiration
Tip 6 – Less fonts, more weights
Different weights within one font family can really strengthen the heading and paragraph arrangement.
This paired with quality text contrast (next up) will create a beautiful reading experience for your user.
Tip: Try stick with two font families (maximum three) in your Landing Page.
Useful links:
- Google Fonts – over 800 free web fonts
- Font Pair – help pairing Google Fonts
- Typekit – beautiful premium web fonts
Tip 7 – More text color contrast
Never have pure black (#000000) text on a pure white (#FFFFFF) page background. Soften the blow with an off-white background and a grey text hierarchy. Example:
#f8f8f8background#111111main headings#222222sub headings#444444paragraph body copy#666666block quotes
Illustrated to the right:
Same goes for pure white on pure black. The contrast is too high. Note the softer color scheme with a dark grey hierarchy to the right:
Tip: Experiment with completely different color palettes within your Landing Page. Start by taking your main brand colors then creating a softer hierarchy of colors.
A quality color scheme is instantly remarkable and can strengthen your branding.
Useful links:
- Colorful websites – for inspiration
- Coolors – great color scheme generator
- ColourLovers – massive collection of color schemes
- Color Lisa – famous art color schemes
Tip 8 – Make sure your Call-To-Action button is an Ace-drawing Maverick
Not crazy Mel Gibson but more classic, winning Gibson.
Try softer pastel colors for backgrounds then use a Maverick (stand out) color like orange, red, green or blue for your call-to-action buttons.
Keep your call-to-action button style consistent. It will remind your user what you want them to do as they scroll.
The ‘Pattern by Etsy’ Landing Page features the same color and styled buttons but they change the wording to correlate with the section copy.
The ‘Oak by Absolut’ Landing Page features strong call-to-action buttons as they match the brand color.
Tip: Make sure the first call-to-action button is above the fold.
Useful links:
- 31 Call-to-Action examples you can’t help but click – by Brittany Leaning
Tip 9 – Polish with Text Kerning and Font Smoothing
It’s incredible how the smallest kerning tweaks can transform a Landing Page design. This example shows subtle kerning in the headings only:
Tip: Different font families act differently, some will need more kerning, some will need none.
By adding just a few lines of CSS code you can really polish a Landing Page design. Here is the code I use on most of my projects:
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
-moz-font-feature-settings: "liga" on;
}
The difference is seen below:
Both are taken off the same Mac device. The right having the additional Font Smoothing CSS styles.
Useful Links:
- Font Smoothing Explained by Krzysztof Szafranek
- Font Smoothing in Webkit and Firefox by David Walsh
Tip 10 – Declutter throughout
Earlier we cut down on images but why stop there. We are not trying to convince the user with as much as possible, it’s as little as possible.
“One does not accumulate but eliminate. It is not daily increase but daily decrease. The height of cultivation always runs to simplicity.” ~ Bruce Lee
Get in the mindset that every piece of content needs to contribute or it must go:
- 2 brilliant testimonials – not 8 average ones.
- 2 highlighted power features, with 4 smaller features below – not a grid of 12.
- Your 8 best wedding photographs – not the past 4 years of work.
Launchday started gathering email address simply with a minimal Landing Page containing intro copy and a demo video. Note the beautiful Maverick call-to-action button too.
Tip: Kill those social share icons, especially the embedded ones. If they are essential, hard code them.
Tip: Replace, don’t add. When you get new testimonials or images, try replace the old ones.
Bonus Tip: Make it remarkable with love
When something is remarkable it sits in the easy-access area of the brain. This is what triggers word-of-mouth, your free form of advertising.
remarkable (adjective): worthy of attention; striking.
Make the user feel you actually give a fuck. Show you care by adding love:
- Style the default UI in 3rd party scripts like Lightbox (more)
- Add subtle CSS load transitions and fades (more)
- Add personality with an emoji (
)
- Add a custom preloader animation (more)
- Highlight the menu item matching the current page section (more)
- Add an x-factor (more)
- Spend time on your website footer (more)
- Give away something of value
Conversely, show you care by removing:
- Misspellings
- Pop-ups
- Scrolljacking
- Lies
- Verbosity
- Jargon
- Clutter
You love your product, you’re proud of it.
Much so you spent a huge amount of time and energy nurturing it’s Landing Page.
Further Resources
- Private Landing Page Feedback – I offer a private feedback service where I record myself interacting with your Landing Page while pointing out issues and offering suggestions.
- Landing Page Inspiration – A collection of over 300 Landing Page references.
- Landing Page Templates – A collection of over 100 Landing Page templates to get you started quicker.
- Landing Page Hosting – Bluehost has an exclusive deal for One Page Love readers at only $2.95 per month for hosting.
Enjoyed the article?
If you really enjoy the article and want to support – I’ve added all these tips into a neat eBook (pay what you want) in PDF and ePub (iBooks) format.
I also threw in a couple bonus tips on “Deconstructing your About paragraph” and “Understanding Storytelling in Landing Pages”. At the back is a printable 20-point ‘Design Checklist’ to ensure your Landing Page is watertight.
Thanks for reading!
Please pass it on to friends if you think it will help them:
http://ift.tt/2jgUjyu
by Rob Hope via One Page Love
19 Facebook Marketing Predictions for 2017 From the Pros
Are you wondering what 2017 might look like for Facebook marketing? If the Facebook changes in 2016 are an indicator, 2017 will be an interesting year for Facebook marketers. To get a grip on what the near future may look like, we tapped the knowledge of 19 social media pros. #1: Paid Ads Come to Facebook Groups [...]
This post 19 Facebook Marketing Predictions for 2017 From the Pros first appeared on .
- Your Guide to the Social Media Jungle
by Lisa D. Jenkins via
Orange — happy 2017
by via Awwwards - Sites of the day
Marie-Michelle Dupuis
by Rob Hope via One Page Love