A Discrete-Event Network Simulator
API
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 
24 
25 
26 import numpy as np
27 import matplotlib.pyplot as plt
28 import ns.core
29 
30 # mu, var = 100, 225
31 
32 
33 rng = ns.core.NormalRandomVariable()
34 rng.SetAttribute("Mean", ns.core.DoubleValue(100.0))
35 rng.SetAttribute("Variance", ns.core.DoubleValue(225.0))
36 
37 x = [rng.GetValue() for t in range(10000)]
38 
39 # the histogram of the data
40 
41 
42 density = 1
43 
44 facecolor='g'
45 
46 alpha=0.75
47 
48 # We don't really need the plot results, we're just going to show it later.
49 # n, bins, patches = plt.hist(x, 50, density=1, facecolor='g', alpha=0.75)
50 plt.hist(x, 50, density=1, facecolor='g', alpha=0.75)
51 
52 plt.title('ns-3 histogram')
53 plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
54 plt.axis([40, 160, 0, 0.03])
55 plt.grid(True)
56 plt.show()