Probablity of a random variable I really feel ashamed to ask this question however I don't have time for revision. Also not a native English speaker, so excuse my lack of math vocabulary.
I am writing a program that requires assigning probabilities to variables then selecting one randomly. 
Example:
Imagine that I have I coin, I would like to assign the probably of 70% to heads and 30% to tails. When I toss it I would like to have 70% chance that the heads appears and 30% tails.
A dumb way to do it is to create an array of cells insert the heads 70 cells and the tail in 30. Randomize them and select one randomly. 
I would like to be pointed to how I can do it mathematically,  Without creating the array.
Edit 1: I also would like to point out that I am not limited to 2 variables. For example lets say that I have 3 characters to select between (*,\$,#) and I want to assign the following probably to each of them * = 30%, \$ = 30%, and # = 40%.
That's why I did not want to to use the random function and wanted to see how it was done mathematically.
 A: Throw your (fair) coin four times. Amongst the 16 possible results, decide that 3 results mean character *, 3 others mean character $, and 4 others mean character #. This leaves you with 6 unallocated results. If one of these is the result of the throw of your four coins, decide that this round was not successful and throw the coin again four times to apply the same allocation procedure. If this new round fails, starts again, and so on until you get one of the 10 allocated results. The mean number of rounds before you are able to produce a character is only 1.6 hence the mean number of coin tosses is 6.4.
A: Stefan Hansen's answer is obviously correct. I myself took this as a "programming question," and here is a one-liner :) 
Let $X$ be uniformly distributed on $[0,1]$. Let "Heads" correspond to $1$, and "Tails" correspond to $0$. Then, the random variable $Y = \min\{\lfloor \frac{10X}{3} \rfloor, 1\}$ has the desired properties.
A: Let $X\sim U(0,1)$ be uniformly distributed over $(0,1)$. Then $X$ has distribution function
$$
F_X(x)=P(X\leq x)=x,\quad x\in (0,1).
$$ Define a new variable $Y$ by
$$
Y(\omega)=
\begin{cases}
1,\quad &\text{if }X(\omega)\leq 0.7,\\
0,&\text{if }X(\omega)>0.7,
\end{cases}
$$
or in other words $Y=1_{\{X\leq 0.7\}}$. Then
$$
P(Y=1)=P(X\leq 0.7)=0.7,\qquad\text{and}\qquad
P(Y=0)=0.3,
$$
Now let $1$ mean heads and $0$ mean tails. In R this easily done by x=runif(1) y=(x<=0.7).

This extends naturally to several variables. If you want probabilities $30\%$, $30\%$ and $40\%$ then let 
$$
Y(\omega)=
\begin{cases}
0, \quad &\text{if }X(\omega)\leq 0.3,\\
1,&\text{if }0.3<X(\omega)\leq 0.6,\\
2,&\text{if }X(\omega)>0.6.
\end{cases}
$$
Do you see the pattern?
A: Mathematically: Let X be a random variable on $\{T,H \}$ such that $X(T)=0.3$ and $X(H)=0.7$.
Using R (a commonly used statistical software), and following your suggested method: 
coin <- c("H","H","H","H","H","H","H","T","T","T") 
sample(coin, 100, replace = TRUE)
the above will give you 100 results of tossing a coin as you described. 
A more straightforward way:
a <- runif(100, 0, 1)
b <- a < 0.3 
the above will give you a vector with the results of 100 coin tosses of your coin, where the value TRUE in the vector stands for a result of Tail. 
