A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sample-rng-plot.py
Go to the documentation of this file.
1 # -*- Mode:Python; -*-
2 # /*
3 # * This program is free software; you can redistribute it and/or modify
4 # * it under the terms of the GNU General Public License version 2 as
5 # * published by the Free Software Foundation
6 # *
7 # * This program is distributed in the hope that it will be useful,
8 # * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # * GNU General Public License for more details.
11 # *
12 # * You should have received a copy of the GNU General Public License
13 # * along with this program; if not, write to the Free Software
14 # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 # */
16 
17 # Demonstrate use of ns-3 as a random number generator integrated with
18 # plotting tools; adapted from Gustavo Carneiro's ns-3 tutorial
19 
20 import numpy as np
21 import matplotlib.pyplot as plt
22 import ns.core
23 
24 # mu, var = 100, 225
25 rng = ns.core.NormalVariable(100.0, 225.0)
26 x = [rng.GetValue() for t in range(10000)]
27 
28 # the histogram of the data
29 n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)
30 
31 plt.title('ns-3 histogram')
32 plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
33 plt.axis([40, 160, 0, 0.03])
34 plt.grid(True)
35 plt.show()